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?

itajackassitajackass Posts: 165Questions: 49Answers: 3

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

  • kthorngrenkthorngren Posts: 21,327Questions: 26Answers: 4,949

    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 use rows().select() or rows().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 the select 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

  • itajackassitajackass Posts: 165Questions: 49Answers: 3

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

  • kthorngrenkthorngren Posts: 21,327Questions: 26Answers: 4,949
    edited May 21

    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

  • itajackassitajackass Posts: 165Questions: 49Answers: 3

    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

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    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

Sign In or Register to comment.