user-select
A user action will cause items to be selected in the table.
Please note - this property requires the Select extension for DataTables.
Description
This event is triggered before items are selected based on an interaction with the table by the end user (typically clicking on a cell in the table).
This event is cancellable - i.e. using e.preventDefault()
or return false;
in the event handler will stop Select from performing any further actions for the selection. This can be useful for cases where you don't want certain items in the table to cause item selection (for example you might have images which perform some other action and should not activate row selection).
Note that this event will not be triggered when the API methods for item selection are used (e.g. row().select()
). It will only be triggered by an end user action defined by select.selector
.
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, cell, originalEvent )
- Parameters:
Name Type Optional 1 e
No jQuery event object
2 dt
No DataTables API instance
3 type
No Item type that will be selected. This can be
row
,column
orcell
.4 cell
No A
cell()
result for the cell that the event was activated by.5 originalEvent
No The original event that was generated by the browser when the end user activated the selection listening event.
Example
Prevent item selection when clicking on an image:
var table = new DataTable('#myTable', {
select: true
});
table.on('user-select', function (e, dt, type, cell, originalEvent) {
if (originalEvent.target.nodeName.toLowerCase() === 'img') {
e.preventDefault();
}
});