deselect
Items (rows, columns or cells) have been deselected.
Please note - this property requires the Select extension for DataTables.
Description
This event is triggered whenever items (rows, columns or cells) are deselected in a DataTable, and provides information about which item(s) have been deselected.
Please note that for performance reasons only a single event is triggered for each deselection action. The result is that if multiple items are deselected in a single action, each item deselected does not receive its own event, but rather the information about the deselected 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:
Name Type Optional 1 e
No jQuery event object
2 dt
No DataTables API instance
3 type
No Items being deselected. This can be
row
,column
orcell
.4 indexes
No The DataTables' indexes of the deselected items. This can be used with the table selector methods (
rows()
for example). For further information about the item indexes used by DataTables, please refer torow().index()
,column().index()
andcell().index()
as appropriate.
Examples
Get data from rows whenever rows are deselected:
var table = new DataTable('#myTable');
table.on('deselect', function (e, dt, type, indexes) {
if (type === 'row') {
var data = table
.rows(indexes)
.data()
.pluck('id');
// do something with the ID of the deselected items
}
});
Remove a custom class when an item is deselected:
var table = new DataTable('#myTable');
table.on('deselect', function (e, dt, type, indexes) {
table[type](indexes)
.nodes()
.to$()
.removeClass('custom-selected');
});