Best way to add a class when results are filtered?

Best way to add a class when results are filtered?

willmowillmo Posts: 1Questions: 1Answers: 0

I searched the forum, docs and the Google for this but came up empty. Think my keywords like 'class' and 'filter' are a little overloaded. :)

I'd like to add a class to dataTables_wrapper whenever the table has been filtered. I'm using the regular search as well as a couple of custom filters. DT is so fast that I'm not sure my users will be able to tell that they've successfully filtered the table in some scenarios!

I know I can hook into a number of events like draw.dt and, if I could figure out which properties to use, can compare the total number of rows or something but I'm guessing there's a simpler way to tell if the table has been filtered—I just can't find it. table.isFiltered() or something perhaps?

If there isn't, can some one point me at which properties are best/safest to use for comparison? Thank you.

Answers

  • dowzerdowzer Posts: 11Questions: 3Answers: 0

    I am using State Saving and when any filter is applied the users complain that the table is missing information as it keeps the state between page loads and it is not obvious that it is filtered.

    Ideally I would like a way of indicating that the table has been filtered other than appending the text in sInfoFiltered:"(filtered from MAX total entries)"

    I have compared the code generated for div.datatables_info and it does not seem to change when filtered so there does not appear to be a class I can attach this to.

    Even if I can just make the whole datatables_info class have a coloured background or different coloured print?

    The current way of indicating it is filtered is just too subtle :)

  • allanallan Posts: 63,124Questions: 1Answers: 10,397 Site admin

    The information from the page.info() method can be used to determine if the table has been filtered or not. That could be called in draw or drawCallback to modify the class as required.

    @dowzer - I think page.info() would also give the information that you need.

    Allan

This discussion has been closed.