knockout and datatable stop working after sorting

knockout and datatable stop working after sorting

kenneth_eaglekenneth_eagle Posts: 2Questions: 0Answers: 0
edited February 2014 in General
I found an interesting behavior with the knockout prototype, http://datatables.net/dev/knockout/.
The prototype stop working after re-sort the table. I used setTimeout for updating a field after 5 sec. Within that 5 sec time range, I sort the table to a different order, then field won't get updated. Does anyone experiencing the same problem?

Replies

  • kenneth_eaglekenneth_eagle Posts: 2Questions: 0Answers: 0
    Just found out setting all rows to invalidate instead of setting 1 row invalidate will fix the problem. Not sure will this affect performance.

    $.each(this, function (key, value) {
    self[key].subscribe(function (val) {

    // Find the row in the DataTable and invalidate it, which will cause DataTables to re-read the data
    //var rowIdx = dt.column(0).data().indexOf(self.Id());
    //dt.row(rowIdx).invalidate();

    // set all rows invalidate
    dt.rows().invalidate();
    });
    });
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    A full invalidate will hit performance a bit, but it won't be too bad unless you have a really large table.

    I've been working on a `dt-foreach` binding which might be a bit more intuitive with Knockout rather than the horrendous mess of the observable arrays and objects.

    Could you drop me a message ( http://datatables.net/contact ) with your e-mail address if you are interested in taking an early look at it?

    Allan
This discussion has been closed.