Custom checkbox based filter no longer working i DataTables 1.10+

Custom checkbox based filter no longer working i DataTables 1.10+

tomas_eklundtomas_eklund Posts: 14Questions: 1Answers: 0
edited March 2015 in DataTables 1.10

I have implemented a custom filtering feature using a hidden column containing machine id's and a UI with checkboxes to show only the rows matching the selected machines. It worked well in DataTables 1.9.0. The code for the custom filter looks something like this (we're using the old API because the application was developed long before the release of 1.10):

// input.filter matches the custom filter checkboxes
$('input.filter').on('change', function () {
    var filter = [];
    $('input.filter').each(function (index, elem) {
        if (elem.checked) filter.push($(elem).val());
    });
    var filterString = filter.join('|');
    table.fnFilter(filterString, 0, true, false, false);
});

We recently purchased TableTools and had to upgrade DataTables to 1.10 for TableTools to work. Now the custom filter doesn't work anymore. This is probably because DataTables 1.10 doesn't allow filtering on columns when bSearchable is set to false.

We've set bSearchable to false on the hidden column because we do not want the text (search box) based filtering to apply to the hidden column as it would be very confusing for users to get random hits. Also we can not downgrade to DataTables 1.9 because we want to use TableTools that we purchased. Is there any way to force fnFilter to search on the column even though bSearchable is set to true for that column? Or what fix would you recommend?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    edited March 2015 Answer ✓

    Hi,

    Interesting that this worked in 1.9 - that looks like a bug! A column marked as not searchable shouldn't have been searchable. So while this appears to be a backwards compatibility issue, it isn't one that I think should be corrected (as the old behaviour was a bug).

    So what I think would be required here is a custom filtering plug-in that will apply your filtering, to the column that is marked that it shouldn't be filtered by DataTables' internal methods.

    I've updated your fiddle showing how this might be done.

    We recently purchased TableTools

    Its worth pointing out that TableTools is MIT licensed and purchase isn't required (it isn't actually available for sale!). Editor is available for purchase, it might be Editor that you purchased.

    Regards,
    Allan

  • tomas_eklundtomas_eklund Posts: 14Questions: 1Answers: 0

    Thank you very much. Excellent support!

    You're right. We purchased Editor, but ended up using just TableTools for now. Sorry for the confusion.

This discussion has been closed.