{hero}

select

Since: Select 1.0.0

Items (rows, columns or cells) have been selected.
Please note - this property requires the Select extension for DataTables.

Description

This event is triggered whenever items (rows, columns or cells) are selected in a DataTable, and provides information about which item(s) have been selected.

Please note that for performance reasons only a single event is triggered for each selection action. The result is that if multiple items are selected in a single action (shift click in the os selection style for example) each item selected does not receive its own event, but rather the information about the selected items is conveyed in an array.

Additionally, as with all DataTables emitted events, this event is triggered with the dt namespace. As such, to listen for this event, you must also use the dt namespace by simply appending .dt to your event name (this is done automatically when using on() and one()).

Type

function function( e, dt, type, indexes )

Parameters:

Examples

Get data from rows whenever rows are selected:

var table = new DataTable('#myTable');

table.on('select', function (e, dt, type, indexes) {
	if (type === 'row') {
		var data = table
			.rows(indexes)
			.data()
			.pluck('id');

		// do something with the ID of the selected items
	}
});

Add a custom class when an item is selected:

var table = new DataTable('#myTable');

table.on('select', function (e, dt, type, indexes) {
	table[type](indexes)
		.nodes()
		.to$()
		.addClass('custom-selected');
});