How to update existing row

How to update existing row

Jithu123Jithu123 Posts: 8Questions: 6Answers: 0

Hi,

Can anyone tell how to update row based on some id?I am trying to use this cTable.rows(someId).data( newData ).draw();
But it is not working.

This question has an accepted answers - jump to answer

Answers

  • Tom (DataTables)Tom (DataTables) Posts: 139Questions: 0Answers: 26
    Answer ✓

    If you are only wanting to update a single row it is better to use row().data() over rows().data().

    someId would have to match row-selector, if you are using the row index selector then someId would have to be an integer.

    For setting the data newData has to either be an array or object, you need to make sure it matches the type of data you've used for the table. If this doesn't match then it wont work.

    An alternative to row().data() is to use row().invalidate().

    Quick example

    someId = 0 ; //first row
    newData = [ "ted", "London", "23" ] //Array, data here must match structure of table data
    cTable.row(someId).data( newData ).draw();
    
    

    Thanks

    Tom

This discussion has been closed.