cancel
Showing results for 
Search instead for 
Did you mean: 
intapiuser
Community Team Member
Community Team Member
Question: How to show the values selected in the dashboard filter as a Blox widget?

Solution:
Our example uses a filter / field called "Fake Names"
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:Fake Names}",
"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:
3. Copy and paste the whole script below:
widget.on("ready", function(w, args) {
 
 //make sure the target BloX text has an "id" attribute of "text-to-change"
 
 var yourFilterTitle = "Fake Names"; //insert your filter title here
 //ASSUMPTION: you're using an ordinary "List"-style filter
 
 var filterDetails = w.dashboard.filters.$$items.find(function(element){
  return element.jaql.title === yourFilterTitle;
 }).jaql.filter;
 
 if(filterDetails.all === true) {
  $("#text-to-change").text(yourFilterTitle + ": All")
 } else {
  $("#text-to-change").text(yourFilterTitle + ": " + filterDetails.members.join(", "))
 }
 
});
4. Change the variable yourFilterTitle to whatever your dashboard filter's title is instead of "Fake Names" - presumably something like "Country".

5. Save all the changes, then refresh the dashboard.

I'll show you what my example looks like for "Include All," single-selection, and multiple-selection:

In addition, the following widget script supports cascaded filters, as well as exclusions.
//========================   Configuration  ================================
var yourFilterTitle = "Filter Title Goes Here";
//==========================================================================

widget.on("ready", function(w, args) {
 
 var filterDetails;
 
 //Loop through all filters
 prism.activeDashboard.filters.$$items.forEach((itemFilter) => {
  
  //if the filter is cascaded
  if(itemFilter.isCascading == true){
   //loop through the levels
   for(var k=0; k<itemFilter.levels.length;k++){
    //If the filter title is equal to FilterName (the target filter)
    if(itemFilter.levels[k].title == yourFilterTitle){
     filterDetails = itemFilter.levels[k].filter
    }
   }
  }
  
  //If the filter is not cascaded:
  else{
   //If the filter title is equal to FilterName (the target filter)
   if(itemFilter.jaql.title == yourFilterTitle){
    filterDetails = itemFilter.jaql.filter
   }
  }
 });
 
 if(filterDetails.all === true) {
  $("#text-to-change").text(yourFilterTitle + ": All")
 }else if(filterDetails.exclude){
  $("#text-to-change").text(yourFilterTitle + ": NOT " + filterDetails.exclude.members.join(", "))
 } else {
  $("#text-to-change").text(yourFilterTitle + ": " + filterDetails.members.join(", "))
 }
});
Comments
barretd
7 - Data Storage
7 - Data Storage

Dear @intapiuser,

Thank you so much for sharing this script!

Unfortunately, this script does not work when exporting the dashboard to PDF. Would you have a fix for this problem?

Many thanks in advance

Dave

Jake_Raz
8 - Cloud Apps
8 - Cloud Apps
//ASSUMPTION: you're using an ordinary "List"-style filter

Is there a way to get this to work with other filters, like a "Text/Contains"-style filter? If so, I'd also be interested to know if it's possible to differentiate between what the user has typed into the filter vs the actual value being selected by the filter. For instance, if they type "Norton Rose", then the actual value being selected is "Norton Rose Fulbright US LLP [Houston]" (because that's the only item that contains 'Norton Rose'). I know BloX can display the latter (the full value name) but can it display the former (what the user typed)? 

Version history
Last update:
‎03-02-2023 08:31 AM
Updated by:
Contributors
Community Toolbox

Recommended quick links to assist you in optimizing your community experience:

Developers Group:

Product Feedback Forum:

Need additional support?:

Submit a Support Request

The Legal Stuff

Have a question about the Sisense Community?

Email community@sisense.com