Filter selections in Blox widget
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:
(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
4 comments
Assaf Hanina
·1 year agoHey Jake_Raz ,
Please find example of the Use Case
Notes:
it also check for Disabled and Include all.
Applying bold style can be adjusted also by creating new element in the Blox
Implementation:
Example with Single value:
Example with Multiple values:
Best Regards
Jake Raz
·1 year agoCommunity_Admin slosada - Not sure if you saw my earlier comment, about whether it's possible to make this work with a "Text" filter instead of a List-style filter, since List-style filters aren't always ideal for fields that contain many values.
I had a few other questions as well:
cmdaniels
·1 year agoIf I try adding this more than one time in a dashboard none of the widgets with the script applied display correctly. Is there a solution for implementing this for more than one filter result?
Jake Raz
·2 years agoWould it be possible for this to work with a Text-style filter? The filter I'm using has too many values for a List-style filter to make sense. Rather than making users pick from that, we just use a text "contains" filter that they type in, as its much easier.