Forum Discussion

benson_lv's avatar
benson_lv
Cloud Apps
10-18-2023
Solved

How to synchronize 2 filters

Hi Guys,

The requirement is that i have a dashboard need to access 2 different datasource.

The 1st widget(table) is extract data from datasource 1, and there is a filter1: serial number

The 2nd widget(table) extract data from datasource 2. and the 2nd table also have a column named serial number.

We want to achieve that when user do a filter by filter1, the widget1 data refreshed, and also impact to the 2nd widget to reload data base on the filter 1's selection immediately.

As i know the filter is also mapping to a special datasource, so it seems not impact widget 2 when i change filter1's value. Any one knows how to do this?

I also try to add 2 different filters, 1st filter is for widget1, 2nd filter is for widget2. Is there a work around solution that 2nd filter can synchronize with 1st filter?

 

 

8 Replies

Replies have been turned off for this discussion
  • ILLIA's avatar
    ILLIA
    Sisense Employee

    Hello!

    Kindly advice you to use 'filterschanged' (https://sisense.dev/guides/customJs/jsApiRef/dashboardClass/#filterschanged) event to develop dashboard script with the following logic:
    - when 'filterschanged' is triggered and there is Filter1 in the arguments (can be checked by jaql.dim), update Filters2 filter property to be the same using dashboard object and dashboard.refresh() or native methods to update filters such as filters.update (https://sisense.dev/guides/customJs/jsApiRef/dashboardClass/dashboard-filters.html#:~:text=item-,update,-remove

    Best regards,

  • Hello, we are trying to achieve the same thing - linking filters together. But, these filters are also linked to different data sources to the parent filter.

    I've added code to the filterschanged event, I'm correctly setting the "child" filters based on the parent filter, and then calling the dashboard refresh.  The filters get updated correctly, the dashboard appears to refresh, but any widget attached to the "child" filters are not getting updated. If I hit ctrl+f5, they do update.

    Any assistance would be great as we have a particularly tricky customer wanting this resolved

    • ILLIA's avatar
      ILLIA
      Sisense Employee

      Hello!

      Could you please advice if you can share your current script in order to check it? 

      Best regards,

      • chriskerrison21's avatar
        chriskerrison21
        Cloud Apps

        sure, here is the script. We have 5 filters, each pointing to a different data source. the top level filter is enabled, the other 4 are locked, but these should be automatically set based on the values selected in the top filter. 

         

        dashboard.on('filterschanged', function(se, ev)
        {
        if (ev != null && ev.items.length > 0 && ev.items[0].jaql.table == "AT Structure") -- this is the top level / enabled filter
        {
        --are all items selected? 
        if (ev.items[0].jaql.filter.members == null)
        {
        se.filters.$$items[1].levels[1].filter.all = true;
        se.filters.$$items[1].levels[1].filter.explicit = false;
         
        se.filters.$$items[2].levels[1].filter.all = true;
        se.filters.$$items[2].levels[1].filter.explicit = false;
         
        se.filters.$$items[3].jaql.filter.all = true;
        se.filters.$$items[3].jaql.filter.explicit = false;
         
        se.filters.$$items[4].levels[1].filter.explicit = false;
        se.filters.$$items[4].levels[1].filter.all = true;
         
        se.$dashboard.refresh();
         
        }
        else
        {
        --Set the "child" filters applicable to the Manager(s) selected in filter 1
        let managers = [];
        for (let i = 0; i < ev.items[0].jaql.filter.members.length; i++)
        {
        if (ev.items[0].jaql.filter.members[i] == 'Dean Thomas')
        {
        managers.push('Portfolio 1');
        }
         
        if (ev.items[0].jaql.filter.members[i] == 'Matt Davis')
        {
        managers.push('Portfolio 2');
        }
         
        if (ev.items[0].jaql.filter.members[i] == 'Rachael Hawkins')
        {
        managers.push('Portfolio 3');
        }
         
        if (ev.items[0].jaql.filter.members[i] == 'Rebecca Dunning')
        {
        managers.push('Portfolio 4');
        }
        }
         
        se.filters.$$items[1].levels[1].filter.all = false;
        se.filters.$$items[2].levels[1].filter.all = false;
        se.filters.$$items[3].jaql.filter.all = false;
        se.filters.$$items[4].levels[1].filter.all = false;
         
        se.filters.$$items[1].levels[1].filter.explicit = true;
        se.filters.$$items[2].levels[1].filter.explicit = true;
        se.filters.$$items[3].jaql.filter.explicit = true;
        se.filters.$$items[4].levels[1].filter.explicit = true;
         
        se.filters.$$items[1].levels[1].filter.members = managers;
        se.filters.$$items[2].levels[1].filter.members = managers;
        se.filters.$$items[3].jaql.filter.members  = managers;
        se.filters.$$items[4].levels[1].filter.members = managers;
        se.$dashboard.refresh();
        }
        }