Filter selections in Blox widget
Question
How to show the values selected in the dashboard filter as a Blox widget?
Answer
Our example uses a filter/field called "Divison_name".
First, in your BloX widget's Editor tab:
1. Set "showCarousel" to "true", but add the following option to make the navigation arrows go away:
"showCarousel": true,
"carouselAnimation": {
"showButtons": false
},
2. Within the specific Text Block / container you want to change, give it an "id" attribute of "text-to-change" and "wrap" attribute as shown in the bolded section below:
"type": "TextBlock",
"text": "{panel:Divison_name}",
"id": "text-to-change",
"wrap": "true",
(Explanation: the "id" helps the widget script in the next steps run properly, and the "wrap" helps all the selected options show up if your user selects lots of them).
Next, edit your widget's script by doing this:
Next, edit your widget's script by doing this:
3. Copy and paste the whole script below:
const filterTitle = "Divison_name";
widget.on("ready", (scope, args) => {
let text = `${filterTitle}: All`;
try {
let foundFilter;
const filter = scope.dashboard.filters.$$items.forEach((item) => {
if (item.levels) {
item.levels.forEach((level) => {
if (level.title === filterTitle) {
foundFilter = level;
}
});
} else if (item.jaql.title === filterTitle) {
foundFilter = item.jaql;
}
});
const { filter: myFilter } = foundFilter;
/*
In Sisense we have different structures of the filter.
For more details about possible options, please, check this article:
https://sisense.dev/guides/querying/jaqlSyntax/#filtering
*/
text = myFilter.members ? `${filterTitle}: ${myFilter.members.join(", ")}` :
myFilter.exclude ? `${filterTitle} excludes: ${myFilter.exclude.members.join(", ")}` :
myFilter.contains ? `${filterTitle} contains: ${myFilter.contains}`: `${filterTitle}: custom filter`;
$("#text-to-change", element).text(text);
} catch(err) {
console.warn(`Filter with title ${filterTitle} was not found`);
$("#text-to-change", element).text(text);
}
});
- Change the variable filterTitle to whatever your dashboard filter's title is instead of "Divison_name" - presumably something like "Country".
- Save all the changes, then refresh the dashboard.
Important: the structure of the JAQL filter is explained in the article below, so the script should be updated accordingly to the structure that is defined in the filter:
https://sisense.dev/guides/querying/jaqlSyntax/#filtering
Updated 12-23-2024
Community_Admin
Admin
Joined October 06, 2021