Can you pass a constant checkbox name into Select with DataTable.render.select('value', 'name')
Can you pass a constant checkbox name into Select with DataTable.render.select('value', 'name')

Description of problem: I'm trying to use Select to have the checkboxes be something users can select and then submit back as part of a form submission. To do that, I'd like the names of the checkboxes to be the same, so that what gets passed back is effectively a list of the checked values (my server side language will turn that into an array of values, which is pretty convenient).
ie, what I"m looking for would be each checkbox Select renders to be like this:
name=MyName, value=Row1Value
name=MyName, value=Row2Value
name=MyName, value=Row3Value
The example page here: https://datatables.net/extensions/select/examples/checkbox/checkbox.html says you can pass in a name and a value for the checkbox rendering, but those both seem to take data out of the table. Is there a way to have the name one just use the value I pass in rather than trying to look something up? I've been trying to do that with the example data on that page without success so far.
Barring that, is there a way to render the checkboxes myself but tell Select to use them?
Thanks.
This question has an accepted answers - jump to answer
Answers
I don't find any documentation for
DataTable.render.select()
. Maybe @allan can add some to the renders docs. It looks like you are correct that you can only reference cells in the row for the value and name attributes.Maybe @allan can update the select renderer to allow for providing hard coded values and names.
You can use
columns.render
to create your own checkbox. For example:https://live.datatables.net/jezahizo/1/edit
Note the
select.selector
is changed from the example you linked so the row is only selected when the checkbox is clicked. Also you can create a header checkbox to be used for select all functionality. There are many thread discussing this on the forum. If you have difficulties with this let us know.Kevin
Bother - looks like I missed the docs for that. Sorry.
The
select
renderer takes two optional parameters. Because they go throughDataTable.util.get()
you could just use a function and return a string - e.g.:I've used
value
for the "value" property - you might want to change that!Allan
render: DataTable.render.select('value', () => 'MyName')
That is what I needed, thanks!