How to deselect rows after ajax.reload call?
How to deselect rows after ajax.reload call?
jstuardo
Posts: 105Questions: 42Answers: 0
Hello,
default behaviour of ajax.reload is to keep selected rows. However, I need the contrary, to deselect rows after ajax.reload completes.
I tried by calling table.rows({ page: 'current' }).deselect(); in draw.dt event, but it did not select anything.
Any help, please?
Jaime
This discussion has been closed.
Answers
This thread has the same question.
Kevin
I'm afraid but it did not work.
I have placed exacly the same code:
But it did not deselect anything. In other place of the code, I am also using:
To load the grid with search data. After that, I am calling
but it did not work either. I also tried to use the drawCallback but none of my attempts work.
Please give a hint.
Thanks
Jaime
Interesting, it doesn't work exactly as @allan suggested. It seems the
table.rows().deselect();
statement is executed before the rows are actually reselected. See this example:http://live.datatables.net/calibuxe/1/edit
The first button shows the default behavior. The second uses the code Allan provided. The third invokes a listener for the
select
event then usestable.rows().deselect();
. Notice the order of the console statements is different than the second button.You can simply unselect the rows before calling
ajax.reload()
like the forth example.The last button shows that this works. I guess it depends on when/where you are using
table.rows().deselect();
. If you still have difficulties please post or update my test case so we can see the issue.Kevin
@kthorngren Yes, as a workaround, I am calling
table.rows().deselect();
before calling to.draw();
or.reload()
methods. That way it works.However, I think DataTable should have a boolean parameter that one can specify if one want the selection to be preserved or not.
I think this was implemented in DataTable in order to keep selection across multiple pages. That is cool, but it should consider the case when that feature is not wanted.
By the way, in your example, when clicking on the second button, even when Selected rows after deselect = 0, the grid shows selected rows.
Regards
Jaime
Its probably a race condition between the rows being reselected from ajax.reload() and deselecting them using
table.rows().deselect();
.Allan can answer for himself but I suspect the complications of adding a parameter to ajax.reload() would far out weigh just simply calling the deselect() API if you don't want it saved.
Kevin