How to clear custom searchPanes filters in a button function?

How to clear custom searchPanes filters in a button function?

Nick HopeNick Hope Posts: 48Questions: 12Answers: 1

Link to test case:
https://fplform.com/fpl-predicted-points

Description of problem:
I am using a button to select rows in a datatable. In the above linked example, if you click the "Load GWXX Team" button, enter a value such as "7388", it should select 15 rows.

However, in some cases, some selected rows are hidden by searchPanes filters that have previously been set, for example the "You never know" filter which is pre-selected by default (using preSelect). I think it would be better to clear all custom searchPanes filters within my button action function, so that all 15 selected rows always appear immediately after loading. How can I do that?

This is a simplified version of the button definition:

        buttons:[
            {
                text: 'Load GW' + lastgw + ' Team',
                action: function () {
                    deselectRows(); //external function to deselect rows and set column totals to zero

                    //code to select rows and sum columns

                    .catch(err => console.error(err));
                }
            }

Answers

  • Nick HopeNick Hope Posts: 48Questions: 12Answers: 1

    I've since found searchPanes.clearSelections() and tried adding it in my function, as shown below, but it is not clearing the selections:

    buttons:[
        {
            text: 'Load GW' + lastgw + ' Team',
            action: function () {
                $('#players').DataTable().searchPanes.clearSelections();
                deselectRows(); //external function to deselect rows and set column totals to zero
     
                //code to select rows and sum columns
     
                .catch(err => console.error(err));
            }
        }
    
  • sandysandy Posts: 913Questions: 0Answers: 236

    Hi @Nick Hope ,

    Running

    $('#players').DataTable().searchPanes.clearSelections();
    

    in the console clears all of the panes fine. Does your site currently have that button active on it?

    Try putting a breakpoint in after the searchPanes.clearSelections() call and see if SearchPanes is also cleared there.

    Thanks,
    Sandy

  • Nick HopeNick Hope Posts: 48Questions: 12Answers: 1

    Apologies. I was working on my .js file but still pointing to my .min.js file. Doh!

    This is working:

    $('#players').DataTable().searchPanes.clearSelections();
    

    Thanks Sandy.

This discussion has been closed.