Forum Discussion
set active page in report with JavaScript API.
- 9 years ago
Thanks Eric_Zhang.
I was able to resolve this and set the page dynamically.
Instead of fetching the page using page name as mentioned in my intial post, I got an array of all the pages and then set whichever page needs to be active.This worked.
My previous code:
const page = report.page(pageName);
page.setActive();My current code:
var pages = [];
report.getPages().then(function (reportPages) {
pages = reportPages;
});pages[1].setActive();
Hope this helps someone visiting here for the same issue.
Resurrecting this old post, but I hit this myself, and found a reasonable solution. The pageName setting does work, but the value required is not the "display name" you see in PowerBI, but actually an internal section ID. You can get this value by accessing the report in the web version of PowerBI and examining the URL.
Ex, for my report below, my groupID is b5801...a4f, my reportID is 634f...054b, and my pageName is ReportSection50033...a22c
While a little ugly, this lets you skip a double page load - I was having trouble with your solution above, as it's dependent on the timing of the report load. I achieved a workable solution by putting the page setter in a report loaded event, but I didn't like the user experience, as the default page (whatever I happened to edit last) would have to load before the desired page would load. Using the direct method with the internal ReportSection{ID} worked a lot cleaner.
Thanks for sharing. This works for me perfectly.
Also, for someone who has the same issue with bookmark, I'd like to add that the bookmark setting works the same way! Bookmark name setting just doesn't work when loading. I've been searching for the solutions. And it finally worked when I tried also with the GUID in the url, instead of the bookmark name. Like this
embedConfig={
...
'bookmark':{
"name":"Bookmarkfdc07f*******120"
}
You can get the GUID in the url with your target bookmark on.
app.powerbi.com/groups/.../ReportSectiond...?bookmarkGuid=Bookmark6...1