render.select() but not for all rows
render.select() but not for all rows
itajackass
Posts: 165Questions: 49Answers: 3
Hi, is it possible to exclude some rows from being selectable, by NOT RENDERING the checkbox?
Actually I use this piece of code:
{
orderable: false,
render: DataTable.render.select(),
className: 'dt-select',
targets: 0
}, ...
But this code create a checkbox for ALL rows.
I'd like instead NOT RENDERING the checkbox when a row has a specific class, for example ("hide-select" class):
<tr><td></td><td>Some data</td></tr>
<tr><td></td><td>Some data</td></tr>
<tr class="hide-select"><td></td><td>This is a non checkable row</td></tr>
<tr><td></td><td>Some data</td></tr>
Then workaround is using this, but the checkbox is rendered and disabled then:
table.on('select', function(e, dt, type, indexes) {
if (type === 'row') {
var rows = table.rows(indexes).nodes().to$();
$.each(rows, function() {
if ($(this).hasClass('hide-select')) table.row($(this)).deselect();
})
}
});
Answers
Use "rowCallback" and hide the checkbox whenever the row has class 'hide-select'.
Here is an example which is slightly different. I don't use a checkbox for select but I also want to exclude certain rows from being selected.