Hi duc_resolvevn , looks like you use the same script/class three times. Try utilizing a unique class when implementing the script multiple times for different widgets on the same dashboard. In BloX editor:
"class": "addPlaceholder1" //for BloX widget 1
"class": "addPlaceholder2" //for BloX widget 2
//etc..
In the Script editor for the widget, use the tempFilter and selector according to your needs:
///for the first widget replace the following rows in the widget script///
var tempFilter = 'First Filter';
///***///
$('.addPlaceholder1').prepend('<option value=\"\" disabled selected>'+tempFilter+'</option>');
///for the second widget they will be different:///
var tempFilter = 'Second Filter';
///***///
$('.addPlaceholder2').prepend('<option value=\"\" disabled selected>'+tempFilter+'</option>');
If the filter is deleted/cleared, the dashboard contains no filters but you want to display the default value, the previous script can be modified as follows:
widget.on('ready', (w, args) => {
var tempFilter = 'All Items';
// Check if there are any items in $$items
if (window.prism.activeDashboard.filters.$$items.length > 0) {
// Check if the first item has filter members
if (window.prism.activeDashboard.filters.$$items[0].jaql.filter.members) {
tempFilter = window.prism.activeDashboard.filters.$$items[0].jaql.filter.members.toString();
}
}
// Prepend the option with the tempFilter value
$('.addPlaceholder').prepend('<option value="" disabled selected>' + tempFilter + '</option>');
});
Let me know if it works better for you!