Updating AJAX-sourced table data using fnUpdate or the API updates the wrong row?

Updating AJAX-sourced table data using fnUpdate or the API updates the wrong row?

cormipcormip Posts: 2Questions: 1Answers: 0
edited August 2014 in DataTables 1.10

According to the docs, something like this should work:

rowindex = tblNames.api().column(0).data().indexOf(newdata.userid);
tblNames.fnUpdate( [newdata.userid, newdata.name], rowindex ); 

or

tblNames.api().row(rowindex).data([newdata.userid, newdata.name]).draw();

However the wrong row gets updated?!?

Further troubleshooting by dumping data to the console shows:

*data display order and index order are the same

*the indexOf(newdata.userid) method DOES find the right rowindex.

Here's the JSFiddle demonstrating the issue:

http://jsfiddle.net/cormip/wvzntjv7/3/

It feels like I'm missing something simple?

Answers

  • cormipcormip Posts: 2Questions: 1Answers: 0

    SOLVED! Even though display order and index order were identical, it was only once I also specified the 'selector-modifier' did it start updating the correct row:

    rowindex = tblNames.api().column(0, {order:'index'}).data().indexOf(newdata.userid);
    
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    Before it was returning the index of the data position in the array, which was the page order, rather than the row order. Your fix is bob on.

    You might want to also consider using using row().data() rather than the old fnUpdate method (since you are already using the new API): http://jsfiddle.net/wvzntjv7/5/ .

    Eventually I plan to add a function selector option to row() (and friends) so you would be able to do that update in a single statement...

    Allan

This discussion has been closed.