Search code examples
yadcf

Any way to programmatically get a list of all applied filters in yadcf?


Is there a way to programmatically get a list of all applied filters in yadcf? Something akin to:

var myTable = $('#example').DataTable();

var state = yadcf.getState(myTable);

And also, can I go the other way around, that is, I am able to programmatically apply filters? Similar to the following?

yadcf.setState(myTable, state);

A use case is that when the user updates the filter, I want to be able to store that filter information somewhere (e.g. a URL), so that the user can retrieve it, share it, and another user can view the table in a similar (if not, identical) state that the earlier user saw.


Solution

  • You are looking for the exGetColumnFilterVal and also for the exFilterColumn ,

    From docs:

    • exFilterColumn Description: Allows to trigger filter/s externally/programmatically (support ALL filter types!!!) , perfect for showing table with pre filtered columns Arguments: table_arg: (variable of the datatable), array of pairs: column number String/Object with from and to, filter_value (the actual string value that we want to filter by) Usage example: yadcf.exFilterColumn(oTable, [[0, 'Some Data 2']]); //pre filter one column yadcf.exFilterColumn(oTable, [[0, 'Some Data 1'], [1, {from: 111, to: 1110}], [2, {from: "", to: "11/25/2014"}]]); //pre filter several columns yadcf.exFilterColumn(oTable, [[0, ['Some Data 1','Some Data 2']]]); // for pre filtering multi select filter you should use array with values (or an array with single value)
    • exGetColumnFilterVal
      Description: Allows to retrieve column current filtered value (support ALL filter types!!!) Arguments: table_arg: (variable of the datatable), column number: column number from which we want the value Usage example: yadcf.exGetColumnFilterVal(oTable,1); Return value: String (for simple filter) / Object (for range filter) with from and to properties / Array of strings for multi_select filter

    I recommend you to go over the docs (inside the yadcf js file) and read about all yadcf goodies.