Update datatable after updating a cell's value

Update datatable after updating a cell's value

MajesticMajestic Posts: 14Questions: 7Answers: 0
edited December 2018 in Free community support

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

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947
    edited December 2018 Answer ✓

    rowCallback is not the place to do this as its called for each row that is displayed. You will probably want to use drawCallback as it is called only once for each table draw.

    I need to set the first cell of the last row with the value of rows.count().

    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

  • MajesticMajestic Posts: 14Questions: 7Answers: 0

    Thank you for your quick answer.
    I managed to do it in drawCallback option :

    lastStep = currentFlowsTable.data().count();
    if($(row).find('.stepCell').text() === "") {
        $(row).find('.stepCell').append(lastStep);
    }
    

    Actually I wanted to set in the cell the value how the number of rows in my datatable

This discussion has been closed.