Skip to content Skip to sidebar Skip to footer

Accept Number Only In Editable Column Td Html

I have problem with validate number only in editable column for my table. so here my html code:

Solution 1:

You can just put allow_only_numbers class to td

also your contenteditable needs to be true

$(".allow_only_numbers").keydown(function (e) {
            if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110]) !== -1 ||
              ((e.keyCode == 65 || e.keyCode == 86 || e.keyCode == 67) && (e.ctrlKey === true || e.metaKey === true)) ||
              (e.keyCode >= 35 && e.keyCode <= 40)) {
                return;
            }
            if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
                e.preventDefault();
            }
        });
<scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><tableborder="1"width="100px"height="50px"><tr><tdclass="allow_only_numbers"contenteditable='true'name="presentase"></td></tr></table>

Solution 2:

you can even use formatter in table like the below code use a function to render the value in table

 <th data-field="DELETE_DOWNLOAD"data-align="center"data-formatter="deleteFileFormatter"></th>

where deleteFileFormatter is the function where value returned from the function will go to the table

Post a Comment for "Accept Number Only In Editable Column Td Html"