Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82117

Multi select with Ctrl+Click

$
0
0
Hi,

For my app I need a DataTable where multiple line selection is done via Ctrl+Click instead of the standard way implemented currently by TableTools.

With some fiddling around I came up with the following code, where you must Ctrl-Click to add a line to the multiple selection. Normal single click will select only the one line that you clicked on (like eg. Windows explorer does it).

oTableTools: {
	"sRowSelect": "multi",
	"fnPreRowSelect": function(e, nodes) {
		if (e) {
			mySelectList = myDeselectList = null;
			if (!e.ctrlKey) {
				myDeselectList = this.fnGetSelected();
				mySelectList = nodes;
			}
		}
		return true;
	},
	"fnRowSelected": function(nodes) {
		if (myDeselectList) {
			var nodeList = myDeselectList;
			myDeselectList = null;
			this.fnDeselect(nodeList);
		}
	},
	"fnRowDeselected": function(nodes) {
		if (myDeselectList) {
			var nodeList = myDeselectList;
			myDeselectList = null;
			this.fnDeselect(nodeList);
		}
		if (mySelectList) {
			var nodeList = mySelectList;
			mySelectList = null;
			this.fnSelect (nodeList);
		}
	},
},

I hope its a good solution and helps someone.

I still need a solution for proper "Shift-Click" behaviour, but I expect this to be considerable more complex, as it involves determining the table lines in between the last clicked position and the current clicked position. My table uses "bDeferRender: true" so I can not perform DOM based searches for 'tr' elements. If anyone knows a good solution then by all means post it here.

Regards,
Stephan

Viewing all articles
Browse latest Browse all 82117

Trending Articles