I'm following this tutorial to implement cell editing in JQuery datatables with MVC4.
Links to the plugins used are:
To achieve the effect of creating the editable datatable you simply have to include the following as part of your script
<script>
$(document).ready(function () {
$('#myDataTable').dataTable().makeEditable();
});
</script>
For each column present in the grid an event is created in the DOM to allow editing.
Where the dataset is very large this has proven to cause significant issues even crashing my browser.
Is it possible to only call the edit logic when the user selects the appropriate column rather than trying to build up a large amount of events in the DOM?
In addition to @CMedina 's answer, please read:
.on() - Direct and delegated events
In addition to their ability to handle events on descendant elements not yet created, another advantage of delegated events is their potential for much lower overhead when many elements must be monitored.
On a data table with 1,000 td
elements in #example
, this example attaches a handler to 1,000 elements:
$("#example td").on("click",function(){
$(this).editable();
})
An event-delegation approach attaches an event handler to only one element, the #example
, and the event only needs to bubble up one level (from the clicked td
to #example
):
$("#example").on("click", "td", function(){
$(this).editable();
})
I don't use makeEditable() with very large datasets, but you might get a performance benefit from an uplift of some of your versions. I am using:
One alternative is add the event when the user clicking in the td.
$(document).ready(function() {
oTable = $('#example').dataTable();
$("#example td").on("click",function(){
$(this).editable();
})
});
Example: https://jsfiddle.net/cmedina/7kfmyw6x/32/
Now, if you do not want to edit all the columns you can assign the event editable only for some columns per class
var oTable = $('#table_id').dataTable(
{
"bSort": false,
"sPaginationType": "full_numbers",
});
$('td.editable_class', oTable.fnGetNodes()).editable('editable.php', {
"callback": function( sValue, y ) {
var aPos = oTable.fnGetPosition( this );
oTable.fnUpdate( sValue, aPos[0], aPos[1] );
},
"submitdata": function ( value, settings ) {
return {
"row_id": $(this).data('id'),
"column": $(this).data('column'),
};
},
"height": "17px",
"width": "100%",
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With