DataTables Checkbox Selection with Columns Configuration Option
DataTables Checkbox Selection with Columns Configuration Option
This page:
https://datatables.net/extensions/select/examples/initialisation/checkbox.html
shows how to add integrated row selectors in the form of checkboxes. The example on the aforementioned page uses columnDefs, which does not require all columns to be specified.
I would like integrated checkbox functionality, but due to other constraints of a complex design, I am also using the "columns" option.
https://datatables.net/reference/option/columns
My understanding is that the columns option specifies the output and parameters of each column, and further that it requires all columns to be specified. In that case, how can the integrated checkbox functionality be "passed through" when also using the "columns" option?
Thanks,
Ryan
Answers
You can use
columns
andcolumnDefs
simultaneously. This link explains the priority of the options between the two.You can define the row selection checkbox in
columns
like this:The key is to set
data: null
.Kevin
This looked like it would solve the problem, but it didn't work.
When I specify:
either with or without
and
as my header, what I see is a table with a totally empty first column and the rest of the columns displayed as I want and expect. No checkboxes appear. Thank you for the help so far. Can you offer any other suggestions?
Ryan
Have you included the select CSS and JS? The
select
CSS contains the config to display the checkboxes.You only need to define the checkbox in either
columns
orcolumnDefs
. But having it in both should work.Kevin
No I hadn't. All working now; sorry about that. Your time wasn't in vain, though. I would have needed the first response even without my silly oversight.
Thank you!