looking to see what filers are applied

looking to see what filers are applied

crcucbcrcucb Posts: 72Questions: 23Answers: 0

I am trying to determine what filters are applied. I have the below code off a button and I am testing with a global filter and a filter on a column using the search builder. The first part passes but writes out undefined to the console. The second part loops through but doesn't indicate that there are any filters in place.

  {
               text: 'What is filtered',
                action: function (e, dt, node, config) {
                if ($('#maintable').find('input[type=search]').val() == '') {
                     // Table is not filtered
                     console.log('not filtered ');
                  } else {
                     // Table is filtered
                     
                     console.log(' filtered ', $('#maintable').find('input[type=search]').val());
                     
                 };
                 
                        var dtable = $('#maintable').DataTable();
                        
                        maintable.columns().every(function () {
                      var column = this;
                      var columnIndex = column.index(); // Get the column's index
                      var currentFilter = column.search(); // Get the current search string for this column

                     if (currentFilter !== '') {
                        console.log('Column ' + columnIndex + ' has a filter applied: "' + currentFilter + '"');
                        // You can perform further actions here based on the filtered column
                        } else {
                        console.log('     Column ' + columnIndex + ' does not have a filter applied.');
                       }
                      });
                        
                    
                   
                  }

This question has an accepted answers - jump to answer

Answers

Sign In or Register to comment.