Is it possible to filter by row & column?

Is it possible to filter by row & column?

hAtul89hAtul89 Posts: 12Questions: 7Answers: 0

I'm currently running this code:

myTable.columns('.seto', true, false).search(types, true, false).draw();

to filter my table - by column.

I want to add an other layer of filtering - by row class ("if row has class") - somthing like the described here:
https://stackoverflow.com/questions/44637704/jquery-datatables-filter-row-with-specific-class

How do I combine both?

Answers

  • hAtul89hAtul89 Posts: 12Questions: 7Answers: 0

    This is what I have tried till now.

    if (heavy) {
    
        jQuery_3_3_1.fn.dataTable.ext.search.push (
            function (settings, data, dataIndex) {
                return $(dataTables.myTable.row(dataIndex).node()).hasClass('light-editor');
            }
        );
        // this.myTable.draw();
    } 
    else {
        jQuery_3_3_1.fn.dataTable.ext.search.pop();
        // dataTables.myTable.draw();
    }
    

    doesn't work well.
    Filters the first time -after playing around with the filters it leaves me with 2 rows :(

  • kthorngrenkthorngren Posts: 21,309Questions: 26Answers: 4,948

    Without seeing your code in action its hard to say what the problem is. Do you get any errors in your browser's console?

    I think instead of pushing and popping the search API I would just push it once and use the if statement inside the function to control whether it checks for heavy. I would also change the selector in line 5 to make it more generic. Here is an example with my suggested changes:
    http://live.datatables.net/sirevege/1/edit

    Kevin

This discussion has been closed.