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')

TridusTridus Posts: 2Questions: 1Answers: 0
edited June 2 in Free community support

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

  • kthorngrenkthorngren Posts: 22,019Questions: 26Answers: 5,082

    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

  • allanallan Posts: 64,521Questions: 1Answers: 10,666 Site admin
    Answer ✓

    Bother - looks like I missed the docs for that. Sorry.

    The select renderer takes two optional parameters. Because they go through DataTable.util.get() you could just use a function and return a string - e.g.:

    render: DataTable.render.select('value', () => 'MyName')
    

    I've used value for the "value" property - you might want to change that!

    Allan

  • TridusTridus Posts: 2Questions: 1Answers: 0

    render: DataTable.render.select('value', () => 'MyName')

    That is what I needed, thanks!

Sign In or Register to comment.