Filter by checkbox

Filter by checkbox

imhalfpirateimhalfpirate Posts: 9Questions: 0Answers: 0
edited January 2012 in DataTables 1.8
I'm using Flexbox to show a very large list of items (about 2,000) with checkboxes in one of the columns. Some are checked and some are left unchecked. I want to create a dropdown filter called "checked" and "all" where "checked" will only show the checked rows and all would show all checked and unchecked rows. How would I go about doing the filtering?

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    What you need to do is make use of the filtering plug-in options of DataTables: http://datatables.net/development/filtering#row_filters . I don't actually have a demo of this in action for checkboxes, but basically you decide, on a per row basis if the row should be included in the display or not (there is example code in the documentation for range filtering).

    Allan
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    I should have said why this is needed - the reason that this approach is needed is that the default filter is done on a string basis rather than DOM elements because it is so much faster for the majority of cases :-).

    Allan
  • imhalfpirateimhalfpirate Posts: 9Questions: 0Answers: 0
    I got the filter plug-in working for other columns but I'm stuck on the checkbox being "checked" filter.

    To build the checkbox from the JSON I'm doing an fnRender than throwing in the value the json returns, which is a string "checked" or blank. In my afnFiltering plug-in I'm alerting the aData[]; and it's bringing back the entire html checkbox . Now the problem I'm having is I can't call aData[].value or aData[].checked etc. So the problem I'm having is that i'm unable to get the value of the fnRendered checkbox. I hope that makes sense :D
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    You need to work on the DOM element, not the data string. You can get the TR node for the row by doing:

    [code]
    var nTr = oSettings.aoData[ iDataIndex ].nTr
    [/code]

    Then you can use standard jQuery expression on that node.

    Allan
  • imhalfpirateimhalfpirate Posts: 9Questions: 0Answers: 0
    edited January 2012
    I finally got it. Hooray!

    To anybody else who needs this:
    [code]
    var nTr = oSettings.aoData[ iDataIndex ].nTr
    var checkbox = $(nTr).find("
This discussion has been closed.