Multiple row selection with Ctrl, Shift
Multiple row selection with Ctrl, Shift
namlesila
Posts: 1Questions: 0Answers: 0
* Multiple row selection with Ctrl, Shift. I have been waiting so long for this function.
Please add it to DataTables.
Action likes Windows Explorer does:
Ctrl + click: add clicked row to the Collection.
Ctrl + Shift + click: add rows from current row to clicked row to the Collection.
Shift + click: clear Collection and then add rows from current row to clicked row to the Collection.
Hope to see it soon!
Thank you very much, I love DataTables!
Please add it to DataTables.
Action likes Windows Explorer does:
Ctrl + click: add clicked row to the Collection.
Ctrl + Shift + click: add rows from current row to clicked row to the Collection.
Shift + click: clear Collection and then add rows from current row to clicked row to the Collection.
Hope to see it soon!
Thank you very much, I love DataTables!
This discussion has been closed.
Replies
Allan
[code]
//////////////////////////////////////////
// Row Selection
//////////////////////////////////////////
jq('#work_orders tbody').on("click","tr", function(event) {
if(!lastChecked) {
lastChecked = this;
}
if(event.shiftKey) {
var start = jq('#work_orders tbody tr').index(this);
var end = jq('#work_orders tbody tr').index(lastChecked);
for(i=Math.min(start,end);i<=Math.max(start,end);i++) {
if (!jq('#work_orders tbody tr').eq(i).hasClass('row_selected')){
jq('#work_orders tbody tr').eq(i).addClass("row_selected");
}
}
// Clear browser text selection mask
if (window.getSelection) {
if (window.getSelection().empty) { // Chrome
window.getSelection().empty();
} else if (window.getSelection().removeAllRanges) { // Firefox
window.getSelection().removeAllRanges();
}
} else if (document.selection) { // IE?
document.selection.empty();
}
} else if ((event.metaKey || event.ctrlKey)){
jq(this).toggleClass('row_selected');
} else {
jq(this).toggleClass('row_selected');
}
lastChecked = this;
});
[/code]
I should point out that this won't work with TableTools, since the row selection in TableTools isn't just row based (fnSelectRow etc should be used), but it does work nicely if you are just working with classes. Thanks for sharing this with us!
Allan