cancel
Showing results for 
Search instead for 
Did you mean: 

How to synchronize 2 filters

benson_lv
8 - Cloud Apps
8 - Cloud Apps

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?

benson_lv_0-1697617100780.png

 

 

1 ACCEPTED SOLUTION

ILLIA
Sisense Team Member
Sisense Team Member

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-,upd...

Best regards,

ILLIA

View solution in original post

8 REPLIES 8

ILLIA
Sisense Team Member
Sisense Team Member

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-,upd...

Best regards,

ILLIA

chriskerrison21
8 - Cloud Apps
8 - Cloud Apps

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

Hello!

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

Best regards,

ILLIA

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();
}
}

 

Hello!

Could you please try to use se.refresh() instead of calling this method through $dashboard object? Also could you try to use se.filters.update() method in order to apply filters properly? 
Reference: https://sisense.dev/guides/customJs/jsApiRef/dashboardClass/dashboard-filters.html#:~:text=item-,upd...

Best regards,

ILLIA

Hello

 

se.refresh seems to work. But should we also use the filters.update. if so, do we call this first and then refresh. Also what parameters would we pass into the filters.update method as it needs an object and some flags passing

Hello!

Thanks for the update. 
Please find here a reference to that method here in the article:
https://sisense.dev/guides/customJs/jsApiRef/dashboardClass/dashboard-filters.html

Also you should use update method if you want these changes to be saved on the dashboard, otherwise you may omit update method usage. 

Best regards,

ILLIA

TriAnthony
Sisense Team Member
Sisense Team Member

Hi @benson_lv ,

I recently wrote an article on how to synchronize filters with a dashboard script: Dashboard Script for Automatic Filter Cascading

Hope this is helpful.

-Tri

Tri Anthony Situmorang