Clear a specific filter

I see many scripts that clear all the filters of a dashboard. Is there a way to clear just a specific filter? For example if I wanted to clear just the date range filter of a dashboard instead of the date range and transaction amount fitlers.

Thanks!

Hi Pierre, hope this helps :slight_smile:

 var tokens = {
   "ALL": new dundas.data.ParameterToken({
       "id": dundas.constants.ALL_TOKEN_DEFINITION_ID,
        "caption": "All"
    }),
     "DEFAULT": new dundas.data.ParameterToken({
         "id": dundas.constants.DEFAULT_TOKEN_DEFINITION_ID,
         "caption": "Default"
     }),
     "NULL": new dundas.data.ParameterToken({
         "id": dundas.constants.NULL_TOKEN_DEFINITION_ID,
         "caption": "Null"
     }),
     "OPEN_RANGE_BOUNDARY": new dundas.data.ParameterToken({
         "id": dundas.constants.OPEN_RANGE_BOUNDARY_TOKEN_DEFINITION_ID,
         "caption": "Open Range Boundary"
     })
 };
var parentView = this.parentView;
var viewParameter = parentView.control.getViewParameterByName("<ParameterNameOfTheFilterYouWantToClear>);
// Alternative you can get it by ID e.g parentView.control.getViewParameterById

viewParameter.parameterValue.clearTokens();
viewParameter.parameterValue.clearValues();
viewParameterparameterValue.token = tokens.ALL;
//Or any other token you prefer
// If its a range parameter you would probably want to use instead 
viewParameter.parameterValue.lowerBoundaryToken = tokens.OPEN_RANGE_BOUNDARY;
viewParameter.parameterValue.upperBoundaryToken = tokens.OPEN_RANGE_BOUNDARY;

viewParameter.invalidateParameterValueLastModifiedTime();
viewParameter.refreshAllAdapters();
2 Likes

This solution will definitely work when you reset a filter control to open boundary / all.

However we also have the ability to ‘Reset Filters’ back to what they were when the dashboard was first opened. I outlined this feature and how to use it in code here:

3 Likes