Multiple row selection with Ctrl, Shift

Multiple row selection with Ctrl, Shift

namlesilanamlesila Posts: 1Questions: 0Answers: 0
edited July 2012 in Feature requests
* 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!

Replies

  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin
    edited July 2012
    That would be an excellent addition to the row selection options in TableTools. I've added it too my feature list, although there are a number of other priorities for the DataTables project at the moment, so it might be a little while before this can be implemented. Keep an eye on the release feed for when it does :-)

    Allan
  • WeaponX86WeaponX86 Posts: 40Questions: 0Answers: 0
    edited August 2012
    I wrote this for our site (replace work_orders with the id of your table):
    [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]
  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin
    Nice one :-).

    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
This discussion has been closed.