Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
manashSahoo
Regular Visitor

GetSlicerState from a Custom Slicer

We use embedded Power BI.

 

I have built a custom date slicer.  We allow the user to save various slicer states and then recall them at a later time.  This works fine for the built-in slicers.  I have code that filters visuals from page.getVisuals where visual.type === "slicer".  I then save this.  However, the custom slicer is not included.  I am not surprised by this because I have no idea where to set the visual type.

 

In reference to the link below, in order to use get/set slicer state, I need the visual to be of type slicer.

https://learn.microsoft.com/en-us/javascript/api/overview/powerbi/control-report-slicers#slicer-apis

 

I have searched endlessly but with no luck.  What in the PBIVIZ pipeline defines the control as a slicer?

 

Thank you

2 REPLIES 2
MAwwad
Super User
Super User

 

In order to use the get/set slicer state methods in the Power BI JavaScript API, the custom slicer needs to be defined as a visual of type "slicer". This is typically done by setting the "type" property of the visual when it is created.

If you are using the Power BI Embedded framework to create your custom slicer, you can set the visual type by passing the "type" property in the "visualSettings" parameter of the create method.

For example:

 

Copy code
let slicerSettings = { type: "slicer", slicer: { ... } }; let slicerVisual = powerbi.createVisual(element, slicerSettings);

 

 

Alternatively, you may set the type property with the setVisual method.

 

Copy code
let slicerVisual = powerbi.createVisual(element); slicerVisual.setVisual({ type: "slicer", slicer: { ... } });
 

Make sure that the visual type is set to "slicer" and after that you should be able to use the get/set slicer state methods with your custom slicer.

Please be aware that in order to use getSlicerState the slicer must be in the same page as the visuals that you would like to filter.

Thank you for your response.  

 

If you look at this sample source code for a sample slicer, I don't see where the type is being set.  I would expect to set the type in the contructor, perhaps.

 

Though we are using the embedded framework, we are loading reports from the Power BI Service.  The reports are built using the PBI Desktop where the custom slicer is added, then published to our workspace on PBI.  Then, our web application with the Embedded Framework loads a selected report into the frame.

 

If I have to set the type after the visuals are loaded, then I will need to find the visual from the active page.  The visual's names look like a shorter version of a guid.

 

Helpful resources

Announcements
Fabcon_Europe_Social_Bogo

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.