Update datatable after updating a cell's value
Update datatable after updating a cell's value
Hello,
I'd like to know how change a cell value in Datatables. I need to set the first cell of the last row with the value of rows.count().
Here's a part of my function to create the fill the datatable:
'rowCallback': function(row, data, index) {
lastStep = currentFlowsTable.data().count();
lastRow = currentFlowsTable.row(':last').data();
lastRow.STEP = lastStep;
currentFlowsTable.row(':last').data().STEP = lastStep;
}
But it does not show the updated cell's value. Am I using this in the wrong part of a datatable (I mean rowCallback option) ?
Thank you very much !
This question has an accepted answers - jump to answer
Answers
rowCallback
is not the place to do this as its called for each row that is displayed. You will probably want to usedrawCallback
as it is called only once for each table draw.I suspect you are getting some errors in the browsers console with that code. One option is to use the
footerCallback
as shown in this example:https://datatables.net/examples/advanced_init/footer_callback.html
However that example places the sum or what ever you want in the footer which doesn't sound like what you want.
When you say the value of rows.count() are you wanting the any of the results from the
page.info()
api? or something different. Updating the last row of the Datatable will cause some issues as that value will remain when you sort or go to the next page.EDIT: If you want to just update the HTML of the first cell in the last row without affecting the Datatables data you could do something like this:
http://live.datatables.net/hujexonu/1/edit
Kevin
Thank you for your quick answer.
I managed to do it in drawCallback option :
Actually I wanted to set in the cell the value how the number of rows in my datatable