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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
acarlson
Regular Visitor

Get slicer data from selectionChanged event

Seems like a simple thing to do but I'm not able for figure this one out.

 

I am embedding a visual (slicer), attaching an event handler for "selectionChanged" and just trying to get the values of the slicer.

 

let embedConfiguration = {
    accessToken: psEmbedDetails.token.Token,
    embedUrl: psEmbedDetails.embedUrl,
    id: PageSectionWidget.PowerBIReport,
    pageName: PageSectionWidget.PowerBIPage,
    tokenType: models.TokenType.Embed,
    type: 'visual',
    slicers: [],
    visualName: PageSectionWidget.PowerBIWidget,
    permissions: models.Permissions.All,
    viewMode: models.ViewMode.View,
    filters: [basicFilterCustomer, basicFilterFurnace],
    settings: {
        filterPaneEnabled: false,
        navContentPaneEnabled: false
    }
};

// Get a reference to the HTML element that contains the embedded report.
let embedContainer = $('#psw' + PageSectionWidget.PageSectionWidgetId)[0];

// Embed the visual.
let visual = powerbi.embed(embedContainer, embedConfiguration);
embeddedElements.push(visual);

visual.on("selectionChanged", function (event) {
    console.log(event.detail);
});

 The details are blank for dataPoints and filters. I just want to get the slicer date range (start and end date)

acarlson_0-1637783870982.png

Thanks for any help!

 

2 REPLIES 2
v-rzhou-msft
Community Support
Community Support

Hi @acarlson 

The selectionChanged event is raised whenever the user is changing the selected visual. selectedItems is a list of all selected visuals when more than one is selected.

report: models.IReport
 page: models.IPage
 visual?: models.IVisual
 selectedItems?: models.IVisual[]

For referece: Selector.SelectionChanged Event

You may refer to this offical blog to learn more details about selectionChanged.

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi Rico, thanks for the reply.

 

The selection changed event reference you gave seems to be for .net controls. I'm trying to get it through the power bi embedded javascript api. The timestamp slicer is an embedded visual, is it possible to get the selected items from within the javascript selectionChanged event?

 

This is what is returned from the event parameter

acarlson_1-1638201367287.png

 

I tried using the getSlicerState() but that returns "getSlicerState is not a function" javascript error.

 

visual.on("selectionChanged", function (event) {
                console.log(event);
                let curV = powerbi.get(event.target);
                curV.getSlicerState().then(slicerState => {
                    if (slicerState.filters.length > 0) filteredSlicers.push(slicerState)
                })
            });

 

Thanks!

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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