cancel
Showing results for 
Search instead for 
Did you mean: 

SAC Analytics Designer: Setting and Removing Table Filters via Scripting

carljschmidt
Participant

Hi there,

I am in a situation, where I want to filter a table in SAC via its onSelect() event with the following code:

// The variable `selection` may have two dimensional columns `KeyColumn` and `ValueColumn`.<br>var selection = Table_1.getSelections();
Table_1.getDataSource().setDimensionFilter('KeyColumn', selection[0].KeyColumn);

As the values in KeyColum are unique in my case, the code filters the table on the entry the user clicked on leaving the user with only a single line in the table after the execution of the code. E.g., Table_1 could look like this:

| KeyColum | ValueColumn |
|----------|-------------|
|        1 |           A |
|        2 |           B |
|        3 |           C |
 ...          

To allow the user to get back to the full table after the filtering, I added a Button and implemented its onClick() event as follows:

// Show the active filters on the data source.
var activeFilters = Table_1.getDataSource().getDimensionFilters('KeyColumn');
console.log(activeFilters);

// Option 1 | Resetting the table
Table_1.getDatasource().removeDimensionFilter('KeyColumn');

// Option 2 | Resetting the table (alternatively; assuming that `dimensionsInfo[0]` refers to the column `KeyColumn`)
var dimensionsInfo = Table1.getDimensions();
Table_1.getDataSource().removeDimensionFilter(dimensionsInfo[0])

However, I am struggling to reset the table via the button as neither option 1 nor option 2 have any effect on the filtered table (i.e. the table remains filtered on a single line) and the array activeFilters turns out to be empty.

I know, that there are some posts in the context of this issue, e.g.:


Since none of these posts helped me to resolve this issue, I would be grateful for any support as to how to reset a table via scripting or any explanation of the observed behavior of the two methods getDimensionFilters() and removeDimensionFilter().

Edit 1:
In the described scenario Table_1 is part of a Linked Analysis and the changes made to Table_1 are set to propagate down to other widgets in the story.
While setting the filter for Table_1 works fine in either case, removing the filter only appears to work if Table_1 is on its own and not linked to any other widget in the story. Please see the comments on eeddggaarr's reply below.

Edit 2 (Solution):
The issue has been solved by using an additional InputControl as an agent to propagate the information about the filtering down to the widgets. In contrast to the initial situation of this question, the widgets are linked to the InputControl rather than Table_1 in this approach, which also allows to use the Link Dimensions feature to also propagate the information of the filtering to other models in the story. Please see the comments on eeddggaarr's reply below.


Thanks for your help!

View Entire Topic
William_Yu
Product and Topic Expert
Product and Topic Expert
0 Kudos

Not sure what goes wrong with the script, but I'm wondering if the new feature of 2023 QRC3 would help you in this case, and you don't have to code anything.

https://blogs.sap.com/2023/07/28/whats-new-in-sap-analytics-cloud-release-2023.15/?source=email-glob...

carljschmidt
Participant
0 Kudos

Hi william.yu,

thank you for your reply! I appreaciate the post you mention and the new features it explains.
However, in my situation, I don't want to user to take action directly but rather have that handled in the implemented scripting logic.

But I will definitely keep that in mind for further developments in the future.

Best regards
Carl

Oleks_Master
Participant
0 Kudos

Hi William,

What feature do you mean, please?

BR, Oleksandr

William_Yu
Product and Topic Expert
Product and Topic Expert
0 Kudos

I'm referring to feature 'Table Widget – Filter Member in Table'