Simple Jquery based table cell editor
SimpleTableCellEditor requires JQuery
Allow table content to be edited clientside, with a click inside editable cell or by keyboard navigation.
A ‘cell:edited’ event is triggered if the cell content has been edited and the content changed.
Quick example : https://codepen.io/HugRob/pen/WNbKNZP
<table id="myTableId">
<tr>
<td class="editMe">Editable text</td>
<td>Uneditable text</td>
<td class="feedMeNumbers">Numbers only</td>
</tr>
</table>
<script>
editor = new SimpleTableCellEditor("myTableId");
editor.SetEditableClass("editMe");
editor.SetEditableClass("feedMeNumbers", { validation: $.isNumeric }); //If validation return false, value is not updated
$('#myTableId').on("cell:edited", function (event) {
console.log(`Cell edited : ${event.oldValue} => ${event.newValue}`);
});
</script>
Use tab or [shift + arrow] to navigate around editable cells.
Thanks jaysin586 for you work !
Full parameters exemple :
<table id="myTableId">
<tr>
<td class="editMe">editable numbers</td>
</tr>
</table>
<script>
editor = new SimpleTableCellEditor("myTableId", { inEditClass: "busy" } );
editor.SetEditableClass("editMe", { //tds with .editMe class will be editable
validation: $.isNumeric, //value entered must be numeric
formatter: (val) => { return val * 10; }, //value entered will be multiplied by 10
keys: {
validation: [13, 107, 35], //these keys will trigger validation (evt.which)
cancellation: [27, 109] //these keys will trigger cancellation (evt.which)
}
});
</script>
Default value for cellParams.behaviour :
behaviour: {
tabKeyCauseCursorMove: true, //Allow user to move through editable fields using tab key. Circular rotation
arrowKeyCauseCursorMove: true, //Allow user to move through editable fields using arrow key. Circular rotation
outsideTableClickCauseCancellation: false, //if user end edition by clicking outside the table, cancel edition or save the value ?
anotherCellClickCauseCancellation: false //if user end edition by clicking another cell, cancel edition or save the value ?
}
By default, outsideTableClick and anotherCellClick are set to “false”, the values are saved
cellParams.internals can be overridden.
Default value for cellParams.internals :
{
renderValue: (elem, formattedNewVal) => { $(elem).text(formattedNewVal); },
renderEditor: (elem, oldVal) => {
$(elem).html(`<input type='text' style="width:100%; max-width:none">`);
var input = $(elem).find('input');
input.focus();
input.val(oldVal);
},
extractEditorValue: (elem) => { return $(elem).find('input').val(); },
extractValue: (elem) => { return $(elem).text(); }
};