Checkbox Column

Checkbox Column

Thorlax402Thorlax402 Posts: 2Questions: 0Answers: 0
edited April 2011 in General
Hello,

So I've been trying to figure out how to get a checkbox column working with DataTables all day. My issue is not with the display of them, but with making the checkbox located in "" to toggle all the other checkboxes on and off. I normally have no issue making a jquery function to check all the other boxes, but my normal way of doing it seems to conflict with datatables reloading. For example, when I click on the checkbox in it toggles all the others for a millisecond before the table is reloaded. My initial idea for fixing this was to put a "return false;" line in my click function. This would check all other other boxes just fine, but would not check the box inside of . Since this box can't be checked then it more acts as a "check all" box than a "toggle all" box.

Does anyone have any suggestions for making this work?


Thanks.

Replies

  • Thorlax402Thorlax402 Posts: 2Questions: 0Answers: 0
    Nevermind, I fixed my issue by making the column containing the checkboxes to be unsortable. That way the data doesn't get reloaded when the checkbox is clicked.
  • kevin2012kevin2012 Posts: 7Questions: 1Answers: 0
    Were you able to check all the hidden rows from pagination ? if so, can you post your solution here..

    Thanks.
  • dmcleandmclean Posts: 55Questions: 2Answers: 0
    I have something similar but without pagination (I use scrolling instead) and I have it set up to only check the unfiltered rows.
  • allanallan Posts: 63,538Questions: 1Answers: 10,476 Site admin
    Are you using DataTables 1.9 by any chance? Its very easy with 1.9:

    [code]
    table.$('input', {"filter": "applied"}).prop("checked", true);
    [/code]

    What that is doing is a jQuery selector on all TR elements in the table with the applied filter, and then performing the jQuery action - in this case checking the checkboxes.

    With 1.8 and below, you need to use the plug-in API method fnGetFilteredNodes: http://datatables.net/plug-ins/api#fnGetFilteredNodes . That will get all TR elements, which you can then loop over and do the jQuery thing again. However, 1.9 is lovely for this kind of thing ;-)

    Final beta should be available very soon, and the final release about a week after that.

    Allan
This discussion has been closed.