Problem with selected rows + stateSave + table.ajax.reload + removed data

Problem with selected rows + stateSave + table.ajax.reload + removed data

flowerpowerflowerpower Posts: 5Questions: 1Answers: 0

This is the problem:
I have a dataTable with some rows loaded with ajax from database, I use the table.ajax.reload function (for reloading data every 10 seconds) and the stateSave (for keep selected rows after every reload of data).
1. I select 3 rows and the selected row counter on the table footer correctly say: "3 rows selected".
2. I remove from database one of the selected rows.
3. The table.ajax.reload function runs and reloads the data on the table and now there are a lower number of rows.
4. Now the remaining visible selected rows is correctly 2 (because one is been removed from database) but the rows counter on the footer of the table count a wrong number! The counter say again "3 rows selected" !!!

How can I solve this problem?

Replies

  • allanallan Posts: 62,992Questions: 1Answers: 10,367 Site admin

    That does sound like a bug, although I'm slightly surprised by it since the way it works is to reselect the rows, and if one of the rows that was selected is no longer present, it can't be reselected.

    Can you link to a page showing the issue so we can debug it please?

    Allan

  • flowerpowerflowerpower Posts: 5Questions: 1Answers: 0
    edited September 2018

    I have created this example you need to play with the ajax call for remove some elements from returned json that you have previously selected on the DataTable.
    In this example, you can see another problem that I have posted here: the stateSave doesn't work very well, the selected rows return unselected after the run of table.ajax.reload function, but if you press F5 button or refresh the page this problem disappear, I think is a problem with the Local Storage where the selected elements are stored.

  • allanallan Posts: 62,992Questions: 1Answers: 10,367 Site admin

    If your row id isn't in a DT_RowId property you need to tell Select (and DataTables in general) where it is using rowId. Otherwise it can't know that a row is the same as before.

    Updated example: https://jsfiddle.net/uym5drwh/33/ .

    Allan

  • flowerpowerflowerpower Posts: 5Questions: 1Answers: 0

    Wow!! Yes, you have solved the questions!! Thank you very much!!

This discussion has been closed.