Custom search plugin function in button action?

Custom search plugin function in button action?

DionFDionF Posts: 1Questions: 1Answers: 0

Hi there,
I have tried multiple methods to call a custom search function within a button action to filter rows based on class name.
In my datatable, rows that are overdue have a class called '.red-colour-background' and I have a button at the top of my datatable called 'Show Overdue'.
On clicking this button, I would like the datatable rows to filter to show only rows that include the class '.red-colour-background'

Here is an example of the code.
I call the action function, then define the filter function 'filterOverdue', then I use the custom search plugin to call the function and redraw the table.
The console.info message gets called for every row so it is iterating over the rows, the issue seems to be with the line returning the rows that have the class - return $(table.row(dataIndex).node()).hasClass('red-colour-background'); and getting the custom search plugin to filter on them.

            {
                text: 'Show Overdue',
                id: 'Show Overdue',
                className: 'top mdc-button filter-overdue',
                action: function ( e, dt, node, config ) {
                    // Filter based on class
                    var filterOverdue = function(settings, data, dataIndex) {
                        console.info('Called function');
                        return $(table.row(dataIndex).node()).hasClass('red-colour-background');
                    }
                    $.fn.dataTable.ext.search.push(filterOverdue);
                    table.draw();
                }
            }

Could I please have some help on how to get the filtering to work?

Answers

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

    Look at Kevin's example from this thread. Ignore the SearchPanes bit. It's doing something similar to what you want - adding a search and removing it on a button press.

    Colin

This discussion has been closed.