Hi, as far as I know it is not possible to add multiple filters at once on a single flexmonster instance.
Is there any way to apply multiple filters at once (AND filters) on a flexmonster instance.
For example,
right now, if I want to apply filter on 'Column1', 'Column2' and 'Column3', I have to do
fm.setFilter('Column1', ['column1.[value1]']);
fm.setFilter('Column1', ['column2.[value2]']);
fm.setFilter('Column3', ['column3.[value3]']);
What I want to do is something like,
fm.setFilter(['Column1', 'Column2', 'Column3'], ['column1.[value1]'], ['column2.[value2]'], ['column3.[value3]'])
If all the filters can't be applied, I don't want any one of the filters to be applied. In other words,
I do not want 'Column1' filter OR 'Column2' filter OR 'Column3' filter
I want 'Column1' filter AND 'Column2' filter AND 'Column3' filter.
The only way I can think of achieving this right now is, doing it manually. Apply 'Column1' filter and see if it is actually applied by using fm.getFilter() and comparing the members, and then apply 'Column2' filter if 'Column1' filter is applied properly and so on. If applying any of the filters fail, I remove all the filters.
Is there any possible way to do this right now through Flexmonster API ? Are there any plans to add this sort of functionality in flexmonster in the future ?
Hello Suraj,
Thank you for your question.
You are right. There is no direct way of how this can be achieved, but there is a workaround that you could try using Flexmonster API.
A solution that may be of help is to use the runQuery() method from the API reference. Here is an example of how this can be done:
Short Outline:
1) Define a slice variable.
2) In the columns section you can add the desired columns and their filters.
3) When the flexmonster.runQuery(slice);
line is executed, it will apply AND filters to the data.
Example Code:
var slice =
{
rows: [
{uniqueName: "Country"}
],
columns: [
{
uniqueName: "Destination",
"filter": {
"members":[
"destination.[australia]",
"destination.[united kingdom]",
"destination.[united states]"
]
}
},
{
uniqueName: "Category",
"filter": {
"members": [
"category.[accessories]",
"category.[bikes]"
]
}
},
{
uniqueName: "Color",
"filter": {
"members": [
"color.[yellow]",
]
}
}
],
measures: [
{uniqueName: "Price"}
]
};
flexmonster.runQuery(slice);
Here is a JSFiddle for a better demonstration.
Before changing the filters, you can save the current slice, then set the filters and check if all filters have applied. If not, then with the runQuery()
method you can roll back to the previous slice (the one which was saved before changing the filters).
Please let us know if this works for you.
Best Regards,
Vera
That is a brilliant idea. Thank you 🙂
This changes the entire report? Or am I misunderstanding. Im trying to achieve something similar but i'm loading data from an API, I can't just define a slice because its way more complicated data than things such as destination. Can you provide an example where I can run a query or set multiple filters when i'm loading data from a flexmonster server and not manually defining slices?
Thanks!