DataTables logo DataTables

via Ad Packs
Multiple row selection with Ctrl, Shift
  • namlesilanamlesila
    Posts: 1
    * 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!
  • allanallan
    Posts: 15,488
    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
  • I wrote this for our site (replace work_orders with the id of your table):
    	//////////////////////////////////////////
    	// 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;
    	});
    
  • allanallan
    Posts: 15,488
    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

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Support

Get useful and friendly help straight from the source.

In this Discussion