Filter selections in Blox widget
Updated 12-23-2024
Hey Jake_Raz ,
Please find example of the Use Case
Notes:
Implementation:
{
"style": "",
"script": "",
"title": "",
"showCarousel": true,
"body": [
{
"type": "Container",
"items": [
{
"type": "TextBlock",
"text": "Filter: <span id='filterName'></span> Members: <span id='members'></span>",
"id": "display_filter",
"style": {
"text-align": "center",
"font-size": "20px",
"margin": "20px"
}
}
]
}
],
"actions": []
}​
widget.on("ready", function(w, args) {
// update the filter name
const filter_title = 'Full_name';
const filter_display_name = 'First Name'
// Define the include_all object for comparison
const include_all = {
explicit: false,
multiSelection: true,
all: true
};
// fixed variables
const filters = w.dashboard.filters.$$items;
let members_to_display = '';
let filter_name = '';
filters.forEach(function(item) {
// Check if the filter's title includes the desired value
if (item.jaql && item.jaql.title.includes(filter_title)) {
filter_name = item.jaql.title;
// Check if the filter matches the "include_all" condition
if (
item.jaql.filter && item.disabled === false &&
JSON.stringify(item.jaql.filter) === JSON.stringify(include_all)
) {
members_to_display = '<b>include all</b>';
} else if (item.jaql.filter && item.jaql.filter.members && item.disabled === false) {
// Extract first names from members
const first_names = item.jaql.filter.members.map(name => `<b>${name.split(' ')[0]}</b>`);
members_to_display = first_names.join(', ');
} else {
members_to_display = '<b>Inactive filter</b>';
}
}
});
// Update the Blox elements dynamically
$("#filterName").text(filter_display_name);
$("#members").html(members_to_display); // Use .html() to allow bold tags
});
​
Example with Single value:
Example with Multiple values:
Best Regards