Function to return values of filters applied using SearchBuilder
Function to return values of filters applied using SearchBuilder

Greetings,
I am trying to list down the list of all filters applied using search builder and the query entered into the seach box. Im unable to find an API for that. Please guide.
At present i use the function below to return number of rows on PDF export and i assume a similar case should allow me to list down the search criteria alongside this.
messageTop: function() {
var table = $('#table_id').DataTable();
return 'Secondary Filter returned ' + table.rows({search: 'applied'}).count() + ' result(s)';
},
This question has accepted answers - jump to:
This discussion has been closed.
Answers
You can use
searchBuilder.getDetails()
to get the filters being applied - this example demonstrates that in action.To get the standard search filter, just call
search()
without any parameters.Colin
Hi colin, calling searchBuilder.getDetails() gives me [object Object].
I would like to get a list like below.
'Filter 1' eq 'Query 1'
'Filter 2' eq 'Query 2'
Hi @2008jackson ,
searchBuilder.getDetails()
returns an object. Try passing that throughJSON.stringify()
as the example shows to get it as text.If you are still having issues can you please provide a test case. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Thanks,
Sandy
Hi Sandy,
JSON.stringify(table.searchBuilder.getDetails()) works perfect to see the JSON string however, this doesn't look good on a PDF.
Currently the below is returned.
{"criteria":[{"condition":"contains","data":"Registration","value":["aef"]}],"logic":"AND"}
Would it be possible to show the filter parameters similar to below?
'Registration' contains 'aef'
Yep, you can just print what you want from the object - the object has all the information you need.
Colin
Appreciate the guidance Colin. How would i pick the information from this JSON below since columns Uploaded and Registration are both identified as "data"? Kindly guide.
Hi @2008jackson ,
criteria
is an array so you use a number as an index to access the objects that it contains.criteria[0].data
will give you"Uploaded"
for example.Thanks,
Sandy
My table has 8 columns and since there is a large possible combinations for search builder inputs, is there an option to pretty print this JSON string?
It's just an object containing the data, you can choose to display it anyway you want, with any format you want.
Colin
I've managed to get my desired output using the code below. But a new issue is that the PDF export doesn't work until there is an input from the search builder. The PDF export button displays a spinner only. Console throws error "Uncaught TypeError: Cannot read property 'forEach' of undefined at makeQuery".
How do i skip to proceed to PDF export if no search builder input is made?
Hi @2008jackson ,
Just add a check to make sure that criteria is not undefined...
Thanks,
Sandy
Worked perfectly sandy. Thankyou. Case can be closed.