Select extension with already created tables from DOM, how to keep cell content?
Select extension with already created tables from DOM, how to keep cell content?
![itajackass](https://secure.gravatar.com/avatar/8734d72a9b7f5f8631f74ac3731cbdee/?default=https%3A%2F%2Fvanillicon.com%2F8734d72a9b7f5f8631f74ac3731cbdee_200.png&rating=g&size=120)
Hi, i need to use select extension on an ALREADY created table.
The problem is that if I enable "DataTable.render.select()" on first column, of course selection is automated (also in the header appear the checkbox for selecting all). But I loose all my info about existing checkboxes ( class, name and value for each row ).
Is there any solution to enable "DataTable.render.select()" but keep class, name, values and attributes for the existing checkboxes created via DOM?
Link test: https://live.datatables.net/guqobiyu/1/edit
Answers
Is the goal for using using
DataTable.render.select()
to get a select all check box or something else?Maybe all you need is to add a checkbox to the
th
and userows().select()
orrows().deselect()
to toggle the select all in a click event for the checkbox.I'm not sure how you are using the "class, name, values and attributes for the existing checkboxes" in you code but another option is to add a new column for the
DataTable.render.select()
checkboxes and hide the current column. Use theselect
event, if appropriate, to get the hidden cell's node (cell().node()
) of that row and parse the attributes you are interested in.If this doesn't help then please provide more details of how you are using these chackboxes outside of Datatables select.
Kevin
Hi thanks for the reply.
I also have a custom button that i use to "send a message to selected people".
Click that button i'll loop only selected rows and i add the value of each checkbox in an array. Then this array is used as parameter for destination page to send a custom message to all of those people.
This is only an example. I've different page where multiselect is used to other purpose... But basically, all my columns with checkboxes have a value and a class...so i can use in the loop:
...
myArray.push($(this).find(".classname").val())
Unless I'm mistaken it sounds like the code you have is doing what you want. What additional functionality or fix are you trying to achieve with using
DataTable.render.select()
to render the checkboxes?Kevin
Actually, my old version in all of my page is using this "dirty" code like this example:
https://live.datatables.net/dopirije/1/edit
I'd like to remove all code after the like i commented as "///////******* DIRTY CODE *********///////////////" if it si possible. and use DataTable.render.select() in a better way to keep my "<input type="checkbox" class="idClient" name="idClient[]" value="xxxx">" created on DOM to achieve my button like example
I'm afraid there is no option to use an existing checkbox in place of the generated checkbox for Select. At least, not without added event listeners to trigger the row selection API, which would be perfectly possible, as shown in your test case.
You can now specify a class name for the generated checkboxes, but not a value.
Allan