Non-standard filtering

Non-standard filtering

johnny123johnny123 Posts: 2Questions: 0Answers: 0
edited August 2012 in General
This is a somewhat thorny problem. I have a table where each row has one category. I also have, elsewhere on the page, checkboxes for each category. Every time a checkbox is checked or unchecked I fire an event containing as data the state of the checkbox and the category. What I want to do is to filter the table according to which checkboxes are checked.

The approaches I though of are:
1. Using table.fnFilter. Since the function has no memory of which filters were applied before that's not practical.
2. Keeping a record of the state of the checkboxes. This breaks decoupling of the checkboxes and table.
3. Add an attribute to each row containing the category and write a custom filter based on that. Again, since the sorting function has no memory I'll have to either keep a memory of what filters were applied in the past or query the checkboxes.

Is there any way of solving this more elegantly?

Replies

  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    Sounds like you'll want to use a custom filtering method: http://datatables.net/development/filtering#global_filters . With that you can apply completely custom filtering to each row.

    Allan
  • johnny123johnny123 Posts: 2Questions: 0Answers: 0
    But won't this be reapplied every time I execute it? In other words - I'll probably be losing the previous filters, which I don't want to happen. Or am I getting something wrong here?
  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    > But won't this be reapplied every time I execute it?

    Yes the filer will be applied every table the table is drawn. Thus if you want a cumulative filer, you need to take that into account in your filtering code :-)

    Allan
This discussion has been closed.