First row missing in aiDisplay array after pushing to $.fn.dataTable.ext.search

First row missing in aiDisplay array after pushing to $.fn.dataTable.ext.search

DTaylorDTaylor Posts: 5Questions: 3Answers: 0

I have multiple datatables in my UI. I wrote this function to remove the filters from a specific table, but preserve all of the filters in other tables:

    removeFilters(tableElement: ElementRef) {
        $.fn.dataTable.ext.search = [];
        $.fn.dataTable.ext.search.push(
            function (settings, data, dataIndex) {
                let retVal = false;
                if (settings.nTable.id === tableElement.nativeElement.id) {
                    retVal = true;
                } else if (settings.aiDisplay.indexOf(dataIndex) > 0) {
                    retVal = true;
                }

                return retVal;
            }
        );
    }

This works great when the function is called via the check boxes being unchecked. The issue comes when you sort the table using the sort icons in the UI. For some reason, when you sort it is somehow calling the function that is passed here in the push, though it does not appear to be calling the removeFilters function. Another odd thing about that is it will filter out the first row of each table that is not the table passed to this function. I think that has something to do with the fact that I end up in this push function without having called the removeFilters function and the tableElement reference has an old value.

Answers

  • DTaylorDTaylor Posts: 5Questions: 3Answers: 0

    It took me basically all day to realize I was not doing >= when checking the aiDisplay array and the first item was being removed every time. Ignore this question. I'm an idiot.

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    We've all been there! Glad fixed...

This discussion has been closed.