How to deselect all elements across all pages on serverside table?
How to deselect all elements across all pages on serverside table?

Link to test case: This can be seen in the serverside table example
Description of problem:
I have noticed that when some elements are selected on page 1, then we go on page 2 and select other elements, Deselect All (selectNone) only deselects the elements on the current page, and those on the other pages remain selected.
How can I clear the selection across the entire table?
Thank you!
This question has an accepted answers - jump to answer
Answers
The example you linked to states this:
Basically this means the Select extension operates on the client side rows only which are just the rows displayed on the page. I haven't seen the
select.cumulative()
API before nor the example. The docs aren't posted for the API which @allan will need to look at.I looked through the select code and it looks like the private variable
_select_set
may have been added to keep track of the server side row IDs that are selected. The only thing I could come up with is to create this API plugin:Basically it clears the private variable of row indexes and redraws the table, to update the info element, staying on the same page. See the
draw()
for more details.I modified the example to use the API to deselect all rows in this example:
https://live.datatables.net/yaroyala/81/edit
@allan can comment if there is a better way or if he is planning to provide this functionality. Possibly this API can be added to the select extension.
Kevin
This solution is perfect for my actual situation (just I prefer ctx._select_set.length = 0).
But one limitation is that it does not trigger the corresponding deselect events.
@tschmit
Using
ctx._select_set.length = 0
is probably better. I didn't think about firing thedeselect
event. I don't think theindexes
parameter will be accurate as only the rows on the page displayed can be deselected with server side processing. The indexes are a client side index only and not useful with SSP. Maybe something like this would be better:Updated test case:
https://live.datatables.net/yaroyala/82/edit
Kevin
may be:
with render() preventing the hit to the server and an event with rowIds and not indexes (I agree with you for the event).
You can send the rowIds and not indexes to the
deselect
event. You can add code to determine which is sent to handle them properly as other deselect API calls or user interaction will still send the indexes.I might be wrong but I don't believe there is a
render()
API. The only way I know to refresh the display is withdraw()
. However @allan might entertain a newrender()
API.If you are going to trigger the
deselect
event then you probably will just want to usedt.draw('page');
and not addrows().deselect()
to keep from firingdeselect
more than once.Kevin
Apologies, I need to dash out, but I'll take a more detailed look at this tomorrow and see if I can come up with a way built into Select to do a deselect all.
Allan