Quantcast
Channel: Developer topics
Viewing all articles
Browse latest Browse all 17905

Multi fields slicer and bookmarks

$
0
0

My visual works like a slicer, you can add several categories and each of them is rendered as a HTML list.


With a single category, all is pretty simple because each item of the list is represented by just one selectionId.
With two o more lists, the things become more complex because every item is represented by multiple selectionIds that contain the lowest grain of all categories added.


So, with multiple lists, when the user selects an item, my visual has to pass several selectionIDs to the selectionManager in order to filter the report properly.
It is not a big issue, but my problems start when the user clicks on a bookmark.
In this case, my visual receives a complex filter. Analyzing the filter, I'm not able to know which list was real selected, so I have to select all the values passed.

 

Take a look a these screenshots: the first one shows what the user has selected (just the category Computers), the second one is a fragment of the filter received after a bookmark with the same selection (just the category Computers) is clicked, the third one is the bookmark render.

 

wanted.png

filter.png

not-wanted.jpg

In this example, I don't want to select all the subcategories, just the parent category, but I have to do so, beacuse they are stored in the filter.

 

I tried to solve the issue by using different approaches.
I tried to apply the selection with a BasicFilter instead of selectionManager with multiple selectionsIds, but I'm not able to add different columns to the same BasicFilter or to apply different BasicFilters with host.applyJsonFilter() function.
So I tried an undocumented (and unsupported, I guess) way, inspired by your FilterManager.restoreSelectionIds() function.
Something like this:

 

let category = ...; //DataViewCategoryColumn
let value = ...; //Text value
let fieldExpr = powerbi["data"].SQExprBuilder.fieldExpr({ 
      column: { 
          entity: category.queryName.substr(0, category.queryName.indexOf('.')), 
          name: category.source.displayName 
      } 
});
let expr = powerbi["data"].SQExprBuilder.equal(fieldExpr, powerbi["data"].SQExprBuilder.text(value));
let identity = powerbi["data"].createDataViewScopeIdentity(expr);
let selectionId = (<any>powerbi["visuals"]).SelectionId.createWithId(identity);
this.selectionManager.select(selectionId, true);

The code above works only with selections from the same category, but produces an advanced filter and breaks the report when multiple categories are involved.

 

Can you help me in understanding how to solve my issue?

 

Thanks.


Viewing all articles
Browse latest Browse all 17905

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>