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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Nojustice
Advocate I
Advocate I

SelectAll is not firing dataSelectedEvent in first instance

Hello,

 

We have a report with a multi-select slicer which has the "Select All" attribute added,

 

When the report is rendered the slicer value is of a set value "Value1", if we change that value to "Select All", the dataSelected Event is not fired.

 

It seems like you have to select another options first and then "Select All" for it to eventually decide that the event should be fired

 

Unfortunately I cannot provide an example of this as the sample report on the sandbox does not have the select all option on the multi-select slicers

 

Can this be fixed?

3 REPLIES 3
Nojustice
Advocate I
Advocate I

the code snippet has been supplied.

 

I have contacted MS directly and they have classified this issue as a bug and it is being worked on currently.

I will update this post when I have information to share

Nojustice
Advocate I
Advocate I

I have an example of it here, it is not necessarily the "Select All", on a multiselect and you untick elements it does not fire.

Here is a code example, here I am setting the slicer dynamically to "Abbas MA-01" with SetSlicerState.

If i was to untick "Abbas MA-01" so everything was considered, the dataSelected event does not fire.

 

let loadedResolve, reportLoaded = new Promise((res, rej) => { loadedResolve = res; });
let renderedResolve, reportRendered = new Promise((res, rej) => { renderedResolve = res; });

// Get models. models contains enums that can be used.
models = window['powerbi-client'].models;

// Embed a Power BI report in the given HTML element with the given configurations
// Read more about how to embed a Power BI report in your application here: https://go.microsoft.com/fwlink/?linkid=2153590
function embedPowerBIReport() {
    /*-----------------------------------------------------------------------------------+
    |    Don't change these values here: access token, embed URL and report ID.          | 
    |    To make changes to these values:                                                | 
    |    1. Save any other code changes to a text editor, as these will be lost.         |
    |    2. Select 'Start over' from the ribbon.                                         |
    |    3. Select a report or use an embed token.                                       |
    +-----------------------------------------------------------------------------------*/
    // Read embed application token
    let accessToken = EMBED_ACCESS_TOKEN;

    // Read embed URL
    let embedUrl = EMBED_URL;

    // Read report Id
    let embedReportId = REPORT_ID;

    // Read embed type from radio
    let tokenType = TOKEN_TYPE;

    // We give All permissions to demonstrate switching between View and Edit mode and saving report.
    let permissions = models.Permissions.All;

    // Create the embed configuration object for the report
    // For more information see https://go.microsoft.com/fwlink/?linkid=2153590
    let config = {
        type: 'report',
        tokenType: tokenType == '0' ? models.TokenType.Aad : models.TokenType.Embed,
        accessToken: accessToken,
        embedUrl: embedUrl,
        id: embedReportId,
        permissions: permissions,
        settings: {
            panes: {
                filters: {
                    visible: true
                },
                pageNavigation: {
                    visible: true
                }
            }
        }
    };

    // Get a reference to the embedded report HTML element
    let embedContainer = $('#embedContainer')[0];

    // Embed the report and display it within the div container.
    report = powerbi.embed(embedContainer, config);

    // report.off removes all event handlers for a specific event
    report.off("loaded");

    // report.on will add an event handler
    report.on("loaded", function () {
        loadedResolve();
        report.off("loaded");
    });

    // report.off removes all event handlers for a specific event
    report.off("error");

    report.on("error", function (event) {
        console.log(event.detail);
    });

    // report.off removes all event handlers for a specific event
    report.off("rendered");

    // report.on will add an event handler
    report.on("rendered", function () {
        renderedResolve();
        report.off("rendered");
    });
}

embedPowerBIReport();
await reportLoaded;

// Insert here the code you want to run after the report is loaded
// report.off removes all event handlers for a specific event
report.off("dataSelected");

// report.on will add an event listener.
report.on("dataSelected", function (event) {
    let data = event.detail;
    console.log("Event - dataSelected:\n", data);
});



// Create the filter object. For more information see https://go.microsoft.com/fwlink/?linkid=2153364
const filter = {
    $schema: "http://powerbi.com/product/schema#basic",
    target: {
        table: "Product",
        column: "Product"
    },
    filterType: models.FilterType.BasicFilter,
    operator: "In",
    values: ["Abbas MA-01"],
    requireSingleSelection: true
};

// Retrieve the page collection and get the visuals for the active page.
try {
    const pages = await report.getPages();

    // Retrieve the active page.
    let page = pages.filter(function (page) {
        return page.isActive;
    })[0];

    const visuals = await page.getVisuals();

    // Retrieve the target visual.
    let slicer = visuals.filter(function (visual) {
        return visual.type === "slicer" && visual.name === "93f1e286b34bd2112237";
    })[0];

    // Set the slicer state which contains the slicer filters.
    await slicer.setSlicerState({ filters: [filter] });
    console.log("slicer was set.");
}
catch (errors) {
    console.log(errors);
}


await reportRendered;

// Insert here the code you want to run after the report is rendered

 

v-yiruan-msft
Community Support
Community Support

Hi @Nojustice ,

Could you please provide a code snippet or some screenshots of the dataSelected Event? Does any other slicer not trigger the dataSelected Event when the slicer option is first switched to Select All?

Power BI Embedded dataSelected event not triggered

dataSelected

Best Regards

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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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