Updating existing row of datatable in a correct row position based on row_id

Updating existing row of datatable in a correct row position based on row_id

nathan1812nathan1812 Posts: 17Questions: 7Answers: 0
edited January 2022 in DataTables

Hi there,
I know it seems like a duplicate question since quite a few people have asked the same one in the past. What I'm trying to do is to update a particular row in my datatable based its row id if it meets the condition in my document.addEventListener() function. I'm using these two lines of code below:
var d = table.row( #row_${index} ).data();
table.row().data(d).draw();

However, it did not write the update into the required existing row but overwrote the update to the first row instead... It picked up the correct row (by row_id) so I do not think there is anything wrong with the row_selector. How can I fix this behavior? Any help would be greatly appreciated! Thanks!

P/S: Of course, before thinking about updating one row at a time, what I had done is to re-render the whole table with the updated single row by updating the source data but it's very sluggish and inefficient as it sounds due to the latency of rendering process.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,296Questions: 26Answers: 4,768
    Answer ✓

    table.row().data(d).draw();

    You still need to pass in a row-selector or row() will select the first row. Do this:

    table.row( #row_${index} ).data(d).draw();
    

    Of course, before thinking about updating one row at a time, what I had done is to re-render the whole table with the updated single row by updating the source data but it's very sluggish and inefficient as it sounds due to the latency of rendering process

    Not sure I understand what you are trying to do. Please provide more details.. If you are looping rows and updating them don't use draw(). Use it separately after the loop is complete so it executes once.

    Kevin

  • nathan1812nathan1812 Posts: 17Questions: 7Answers: 0

    Thank you Kevin

Sign In or Register to comment.