cancel
Showing results for 
Search instead for 
Did you mean: 
Community_Admin
Community Team Member
Community Team Member

Question

How to show the values selected in the dashboard filter as a Blox widget?

Answer

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(", "))
 }
 
});
  1. Change the variable yourFilterTitle to whatever your dashboard filter's title is instead of "Fake Names" - presumably something like "Country".

 

  1. 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:

Community_Admin_0-1634631539067.png

 

Community_Admin_1-1634631539179.png

 

Community_Admin_2-1634631539080.png

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
Jake_Raz
9 - Travel Pro
9 - Travel Pro
//ASSUMPTION: you're using an ordinary "List"-style filter

Would 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. 

Version history
Last update:
‎11-10-2023 11:49 AM
Updated by:
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 [email protected]

Share this page: