select.selectable
Set a function that will determine if a row should be selectable.
Please note - this property requires the Select extension for DataTables.
Description
In some data sets you might find that you wish to disallow selection on some specific rows of data. This option provides exactly that ability by allowing you to define a function that will return a value to indicate if a row should be selectable or not based on whatever logic you wish to define.
The function is passed in information about the row and it is strongly recommended that you use the row data to perform your logic check on only to keep the function operation as fast as possible. You could use the table node or even look the row up in the API, but these operations can slow the table down as this function, if defined, can be called frequently.
If this function is not defined (there is no default function), all rows are considered to be selectable.
Type
function selectable( data, tr, index )
- Parameters:
Name Type Optional 1 row
No The row's data source object or array (depending on
columns.data
).2 tr
No The
tr
element for the node. Please note that this might benull
if Ajax loading data and the row has not yet been rendered (seedeferRender
).3 index
No The row's data index in the DataTable (
row().index()
).- Returns:
Return
true
if the row is selectable andfalse
if not.
Default
- Value:
undefined
Examples
Use a data point from the row's data as the selectable flag:
new DataTable('#example', {
select: {
selectable: rowData => rowData.outdated
}
});
Check data in the row to decide it it should be selectable. Also add a class based on the same logic:
new DataTable('#example', {
rowCallback: function (tr, rowData) {
if (rowData[2] === 'New York') {
tr.classList.add('unselectable');
}
},
select: {
selectable: function (rowData) {
return rowData[2] !== 'New York';
}
}
});
Related
The following options are directly related and may also be useful in your application development.