Get page name when user switches to some other page in a report

Viewed 160

I have a report that contains more than 1 pages. Now I want to add a functionality in my report such that whenever I switch to some other page then I get to know the page name so that I can assign my page name value to some global variable

1 Answers

You can add an event handler which will get called when the Report page is changed.

Please follow the below code snippets:

  1. Create the embed configuration object for the report:
const embedConfig = {
        type: "report",
        tokenType: models.TokenType.AAD,
        accessToken: "ACCESS_TOKEN",
        embedUrl: "EMBED_URL",
 };
  1. Get a reference to the HTML DIV element that contains the embedded report:
const embedContainer = $('#embedContainer')[0];
  1. Embed the Report:
const report = powerbi.embed(embedContainer, embedConfig);
  1. Add an event handler on the report object. Inside the event, you can assign the name property of the event object to the global variable:
report.on('pageChanged', event => {
    const page = event.details.newPage;
    globalVar = page.name;
});

Please refer: https://docs.microsoft.com/javascript/api/overview/powerbi/page-navigation

Related