cancel
Showing results for 
Search instead for 
Did you mean: 
Liliia_DevX
Sisense Team Member
Sisense Team Member

How to Use "OR" Filter Condition on a Widget Level | JavaScript

This article provides an example JavaScript code snippet to have the ability to use the "OR" filter condition on a widget level. Currently, the Filter Relations Editor in Sisense allows users to set up dashboard filters with "OR" relations. If there is a need to configure the "OR" filter relation between two filters at the widget level, this JavaScript code snippet might help to achieve your goal. 

Before:

Screenshot 2024-04-26 at 10.33.35.png

 

After:

Screenshot 2024-04-25 at 16.50.37.png


How to use it?

  1. Open a widget in edit mode by pressing the pencil icon. 
  2. Click the three dots menu and choose "Edit Script."
  3. Copy and paste the following script into the "Edit Script" section.
  4. Adjust const filtersOr = ['Category', 'Condition'] with the widget filters names instead of 'Category', 'Condition'.
  5. Press "Save".

 

const filtersOr = ['Category', 'Condition']



widget.on('beforequery', (scope,args)=>{
	let filters = args.query.metadata.filter(f => f.panel === 'scope' && filtersOr.includes(f.jaql.title))
	filters = filters.map(f => f.instanceid)
	args.query.filterRelations = {
        "operator": "OR",
        "left": {
            "instanceid": filters[0]
        },
        "right": {
            "instanceid": filters[1]
        }
}
})

 

Hope it helps you! 🙂

Disclaimer: Please note that this blog post contains one possible custom workaround solution for users with similar use cases. We cannot guarantee that the custom code solution described in this post will work in every scenario or with every Sisense software version. As such, we strongly advise users to test solutions in their own environment prior to deploying them to ensure that the solutions proffered function as desired in their environment. For the avoidance of doubt, the content of this blog post is provided to you “as-is” and without warranty of any kind, express, implied, or otherwise, including without limitation any warranty of security and or fitness for a particular purpose. The workaround solution described in this post incorporates custom coding, which is outside the Sisense product development environment and is, therefore, not covered by Sisense warranty and support services.

Rate this article:
Version history
Last update:
‎04-26-2024 01:54 PM
Updated by: