Support for OS style multi-row selection in fnPreRowSelect
Support for OS style multi-row selection in fnPreRowSelect
Allan,
I've recently been implementing some of the awesome new features in DataTables 1.10.x. One of the most useful features has been the sRowSelect: 'os' option, that allows Control and Shift clicks to quick select and deselect multiple rows. However, when using this to select a plurality of rows for a batch operation, I have encountered a shortcoming in fnPreRowSelect. As the documentation suggests, I have used fnPreRowSelect to filter out rows that should not be selectable (ie disabled), and this works great for single and control-clicked selections. However, a problem arises when the user shift-clicks to select a block of rows. fnPreRowSelect is passed an event, and an array of the nodes that have been selected, but only accepts a return type of boolean. That means that the only course is to return false to throw out the entire operation if the user's selection includes one or more "unselectable" rows, which is sub optimal. I would like to propose that fnRowPreSelect support a return type of boolean, or an array of booleans of the same size as nodes (typically, a map operation). Alternatively, if fnRowPreSelect were invoked once per node instead of once for the batch, that would also satisfy the use case.
I have created a test case on http://live.datatables.net/dutujoqa/1/edit?html,js,console,output that hopefully illustrates what I'm talking about. Any row where the second column (index 1) is 'Javascript Developer' should be unselectable (as you can see in the console). The console output is an array of booleans matching up 1:1 with the nodes selected, and if a 'Javascript Developer' row is selected, there is a false in the output.
Please let me know if I can provide any more information that might help.
Thanks,
-steve
This question has an accepted answers - jump to answer
Answers
Hi Steve,
Thanks for the suggestion - that does sound very sensible.
To be honest, the row selection code in TableTools is a bit of a mess - I've recently been working on two new extensions for DataTables imaginatively called Buttons and Select which succeed TableTools. As such, TableTools will now only receive critical bug fixes rather than new features (your suggestion is probably a little of both!).
Both Buttons and Select really harness the 1.10 API and I think are a big step forward. They haven't been published yet, but the core software for them has been finished - if you are interested in trying the new Select software out, could you drop me a PM and I'll guide you through it.
In Select there isn't a
preSelect
style callback - rather what you would need to do is listen for theselect.dt
event which will give you information about the items selected and you can then immediately deselect the ones you don't want to be selectable.Allan