Is it possible to specify that only some rows are selectable using the Select extension?
Is it possible to specify that only some rows are selectable using the Select extension?
When using the select extension, with multi-select enabled, is there a simple way to specify that there are certain rows we don't want selectable?
I know there's a user-select event which we can use, but if we enable the checkbox column with
columnDefs: [
{
targets: 0,
checkboxes: {
selectRow: true
}
}
]
It will show a checkbox on every single row, even ones the user-select event will prevent from being selected.
When all rows are selectable, you don't necessarily need to tell the user which rows are selectable, but if only certain rows are selectable, it becomes important to have some way to tell them, like the checkbox column. Unfortunately, I can't get this column to only generate checkboxes for the rows that are selectable, and skip all the other rows.
Answers
If you use the row checkbox with the "select" extension there should be an easy way to do this. Use "rowCallback" and for each row you don't want selectable replace the checkbox with something else using css.
https://datatables.net/reference/option/rowCallback
Alternatively you can try with the "select.selector".
https://datatables.net/reference/option/select.selector
I actually used a row selector in combination with rowCallback already. Here it is:
First step: add a class to the rows you want selectable using rowCallback:
Second step: add the row selector:
The above code makes all rows selectable except for those that don't have class "selectRow". The first column of each row generally is not selectable.