cancel
Showing results for 
Search instead for 
Did you mean: 
intapiuser
Community Team Member
Community Team Member
Purpose/Benefit
Sometimes it is convenient to always reset the filters to a default state when opening a dashboard.  This post describes how to achieve this with a little bit of JavaScript.  When users will often be resetting filters to a default state, it is also useful to have a more prominent button to do so.  This post describes how to do this as well (optional).
Prerequisites
None
Steps

STEP 1 - OPEN A DASHBOARD & OPEN THE SCRIPT EDITOR

 
Open the options menu in the upper right corner of the dashboard and choose the Edit Script option (as shown below).
Note: It's not always desirable to do this for all dashboards, so these steps must be taken for each dashboard that you want to have this behavior.
 

STEP 2 - PASTE IN THE FOLLOWING CODE SNIPPET AND CLICK SAVE

window.resetFilters = function(d) { //Function to reset the dashboard filters to the default filters.  Takes parameter 'd' which is a reference to the dashboard
 
 d.filters.clear(); //Clears current filters
 
 d.defaultFilters.forEach(function(filter, index){ //Loop through each default filter and apply to current dashboard filters
  if(index != d.defaultFilters.length - 1){ //Does not refresh filter if it is not the last filter
   d.filters.update(filter,{
    save:true, 
    refresh:false, 
    unionIfSameDimensionAndSameType:true
   });
  } 
  else{//Only refresh dashboard on the last filter
   d.filters.update(filter,{
    save:true, 
    refresh:true, 
    unionIfSameDimensionAndSameType:true
   });
  } 
 })
 
}

dashboard.on('initialized', function(d){    //Resets filters to default when dashboard is first loaded (or refreshed)
 
  resetFilters(prism.activeDashboard); //Resets filters
 
})
(Optional) Include this code snippet after the first to create a larger copy of the reset filters button on the toolbar.  This may be convenient for some users.
dashboard.on('initialized', function(sender, ev){ //Adds filter reset button to the toolbar

 toolbar = $('.actions-box'); //reference to top toolbar
 resetButtonHTML = "<div id=\"toolbarResetButton\" class=\"btn-immutable btn-action\" onclick=\"resetFilters(prism.activeDashboard)\" data-ng-style=\"{height: sizing.toolbar.height, \'border-left-width\': sizing.atoms.midHgap + \'px\'}\" title=\"Restore my default filters\" style=\"height: 50px; border-left-width: 30px;\"><div style=\"background-image: url(../client/resources/ux-controls/images/refresh_48.png); height: 50px; width: 50px; background-repeat: no-repeat; background-position: center\"></div>"" //button HTML with reference to resetFilters() function

        if($('div#toolbarResetButton').length == 0){ //Check to see if filter reset button already exists in DOM 
                toolbar.append(resetButtonHTML); //Adds filter reset button to DOM 
        }
})

STEP 3 - ENJOY!

Your dashboard filters will now reset to their default state when a user opens the dashboard!

Comments
shahamel
7 - Data Storage
7 - Data Storage

By doing this you basically activate something on opening a dashboard. Would also be possible to activiate a blox widget action on opening a dashboard?

I have a bar chart and a blox widget. The blox widget contains an action that creates a plot line in the bar chart. This line will only appear after pressing apply on the action button. Is it possible that this will be activiated as soon as the user opens this dashboard?

DRay
Community Team Member
Community Team Member

Hello @shahamel,

First of all, sorry for the delay. I know this answer has taken a while. These posts from intapiuser were created by an automated migration and are not monitored.

That's a great question. If you haven't found an answer yet, please post your question in the Build Analytics Discussions section. We are happy to help you there.

It looks like there are some similar questions there already, so maybe you can get some answers from those posts. 

Have a great day!

shahamel
7 - Data Storage
7 - Data Storage

Thank you for replying. Even though i have checked the Build Analytic Discussions I have not yet checked if i can used the knowledge there. 

Aside from that i want to thank you for your time 🙂

DRay
Community Team Member
Community Team Member

@shahamel Happy to help! Please let us know if you need any more assistance.

Version history
Last update:
‎03-02-2023 09:51 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 [email protected]

Share this page: