Column control Values are not updating
Column control Values are not updating
Hello,
I have a dynamic datatable in which input controls are creating from ajax call. And this table have more than 10 rows. All the input controls are editable. The data load from ajax call and user can further modify this data. But the problem is i want to send this data to server in json form and when i use
table.rows().data().toArray()
it returns me ajax data that i have load earlier but i want modified data.
i'm using below code to update td,tr but this seem's not to be working condition.
$('#tblCommissionDetails').on('change', 'input', function () {
var tdCell = $(this).closest('td');
//update the value
$(this).attr('value', this.value);
/*$('#tblCommissionDetails').DataTable().draw();
var idx = $('#tblCommissionDetails').DataTable().cell(tdCell).index().row;
var data = $('#tblCommissionDetails').DataTable().cells(idx).invalidate().draw(false);*/
});
Any suggestions will be appreciated.
Regards
Edited by Kevin: Syntax highlighting. Details on how to highlight code using markdown can be found in this guide
This question has an accepted answers - jump to answer
Answers
I would try using
cell().data()
to update the data. Try this in your event handler:If this doesn't help then please provide a link to your page or a test case replicating the issue so we can see what you have to offer suggestions.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
I tried this but still not working.
below is the test case url.
http://live.datatables.net/cosapidi/1/edit.
Your test case has some errors like variables not found. I simplified it here to just replicate the question you are asking. The simpler the test case the better
http://live.datatables.net/pahilasu/1/edit
Your code does work. There are a couple things I needed to fix like removing
{data: 'id}
and usingdata: data.data
to point to the array of rows. The event handler works and updates the Datatables data cache. Change anything in the Selected Item column then click the button to see the results.Kevin
Thanks! now, its working.