Select and serverSide - selected rows are visualy kept after redraw, but Select forget them
Select and serverSide - selected rows are visualy kept after redraw, but Select forget them
hello,
I'm using the serverSide option for a table, along with the select extension, and made my way to get back the selected rows after using the pager.
It uses an array outside DT to memorize the rowId (data.id below) of the selected rows as described here
https://datatables.net/examples/server_side/select_rows.html
'rowCallback': function( row, data ) {\
if ( $.inArray(data.id.toString(), selected) !== -1 ) {
$(row).addClass("selected");
}
};
and uses .on( 'select'/'deselect') methods rather than .on('click') to update the selected array.
BUT
visually it's ok for the user, but not for Select, I guess, since user cannot deselect a row with one clic as it should : this clic actually select the row, from a Select point of view..
the second clic is ok, obviously, it deselects.
something in the callback above is missing to feed Select with the previously memorized rowIds.
What is the best practice ?
How can I trigger a real Select method to select() the row from the row Callback - if applicable ?
do I really need to create a dedicated array for this, can I use some Select internals to work with ? Or save it before a redraw ?
thank you for your time
jerome
This question has an accepted answers - jump to answer
Answers
Yep, you're only adding the class, so Select extension would have no idea it's been selected. Instead of adding the class, call
row().select()
to select the row again, or you can userows().select()
to select them all at once,Colin
I already tried this but well Im not fluent in js.. I don't know how to get the row instance back :
oh ok
many thanks Colin
Jerome