Search code examples
javascripttabulator

How to get a dataFiltered-Callback for a specific Column Header Filters?


as far as I understand there is only the callback dataFiltered, which is used for the whole table. It is triggered by all filters indifferently.

Is it possible to get a callback for a specific single header filter? So that I can call a function as soon as a certain header filter becomes active? I imagine it to be something like this:

{title:"Name", field:"name", headerFilter:true, headerdataFiltered:function()}

Is there possibly a workaround? Thanks a lot! (I would be especially grateful for non-jquery solutions)

Thanks also for this realy wonderful tool Tabulator.


Solution

  • Thanks for your kind words, it is always great to hear that Tabulator is appreciated.

    The reason it is called when any filter is applied is because multiple filters can be applied at once, with Complex Filtering a complex and/or filter set can be applied so it would be hard to isolate down to specific columns in all cases.

    The dataFiltered callback does get passed a list of all currently active filters so you can see if your affected column is in that:

    var table = new Tabulator("#example-table", {
        dataFiltering:function(filters){
        //filters - array of filters currently applied
    
        },
    });
    

    If you need to see if the column has just been filtered you can store a copy of the previous value of this object outside the callback and then compare the old and new values on the next call.

    The other option would be to use a custom editor in the header filter then you could manually decide when the success function is called that initiates the filter and then reference an external function from there