Customized filter
Customized filter
AlainS
Posts: 2Questions: 1Answers: 0
I integrated DataTables in my application, yesterday, and it works fantastic, thanks a lot!
I want to offer my users a selectbox with predefined filters. What is the way to go, to realise that?
For example a filter with all people with a Salary>100.000 and their Lastname starting with an 'A'. And another filter of people with City=Amsterdam and Salary<25.000. Etc.
Thanks!
Answers
If you wanted to use SearchBuilder, you could use the API to load pre-defined searches, as shown in this example.
Otherwise, you'll need a button to load a custom search plugin - there are a few examples here,
Colin
Thanks!
I added the searchBuilder.min.js and .css to the page and the filtering with buttons works well.
But now I want to create my pre-defined custom filters (that my users can select) and result in a an accordingly filtered table.
The name of my (only) table is datatable_1. I wrote a function that is called right after the page is written: datatablesManager(), see below. In that function an eventlistener is defined on the listbox, named 'filter_choice'. When the user clicks on option 1 then I want to overwrite searchBuilder.preDefined. I was hoping that the criteria were used for a new table.draw(). But it doesn't work, after the user selects option 1 the console gives the errormessage: "Uncaught TypeError: Cannot read property 'push' of undefined". This is the line of the error:
$.fn.dataTable.defaults.searchBuilder.push.
I'm afraid I'm approaching things in the wrong way?
Thanks!
Hi @AlainS ,
searchBuilder.preDefined
will only be used when the table is first initialised, not after every draw. That being said, I would advise using thesearchBuilder.rebuild()
method rather than re-initialising the table every time. The example that colin linked is showing this in action. I think it is more likely to do what you are looking for.Thanks,
Sandy