How to update the display value and not the underlying value?
How to update the display value and not the underlying value?
How can I update only the displayed value for a cell that contains an underlying array where a render is being used to display the array.length?
In the example https://editor.datatables.net/examples/datatables/parentChild.html
The user count is conditioned with a render.
var siteTable = $('#sites').DataTable({
ajax: '../php/sites.php',
columns: [
{ data: 'name' },
{
data: 'users',
render: function (data) {
return data.length;
}
}
],
Since this is not persistent data (client display only) I would like to update the displayed values on Add actions and Delete Actions. Seems unnecessary to round trip reloading the table to get the counters adjusted.
Thanks in advance.
This question has an accepted answers - jump to answer
Answers
Hi,
Use
cell().data()orrow().data()to update the underlying data. Then calldraw()to redraw the table with the new information.Regards,
Allan
Thanks for the reply. I was not concerned with updating the underlying data which is an array. What I want to do is to be able to update the number that is being generated by the render on the length of the array. So in your parentChild example each user shows as having 6 users. Functionally I want to add a new user and update the user count to 7 without doing the round trip to the server for a table update. I am envisioning having thousands of rows in the main table that each could have upto 10 child data counters. So again just trying to avoid the round trip of each change of child data. Is this possible?
I would use
cell().data()to update the array to add the new user then whendraw()is called the render function will run updating the cell's display:Here is a simple example:
https://live.datatables.net/vovacoxi/1/edit
Click on a Position cell to update the User's array and update the array length dsiplay.
Kevin
You can do something similar with
row().data()if that is more appropriate for your solution.Kevin
Thanks kthorngren. That is a nice simple solution.