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

The Fabric Community site will be in read-only mode on Monday, Feb 24 from 12:01 AM to 8 AM PST for scheduled upgrades.

Reply
andyparkerson
Advocate I
Advocate I

Determine LayoutType of Embedded PowerBI report

How do I determine whether a report is loaded in MobilePortrait or MobileLandscape via the Javascript API?

 

I want to add a button on the embedding page that will toggle between mobile and desktop versions of a report.

 

I can change between the two with the report.updateSettings() function, but I can't figure out how to determine the current settings. Specifically what the layoutType setting is currently set to.

 

Thanks,

Andy Parkerson

1 ACCEPTED SOLUTION
andyparkerson
Advocate I
Advocate I

I figured this out. At load, you can look at the configuration settings, which are stored in the report object.

let report = powerbi.get(document.getElementbyId('embed-container'));
let models = window['powerbi-client'].models;
let isMobile = report.config.settings.layoutType == models.LayoutType.MobilePortrait;

 The variable isMobile is a boolean that shows you if the report is mobile or not.

 

Caution: If you change the layout to MobilePortrait with the report.updateSettings() function, this will no longer work. You could keep track of that in the document at each toggle.

function toggleMobile() {
    let settings = document.isMobilePortrait ? {layoutType:window['powerbi-client'].models.LayoutType.MobileLandscape} : {layoutType:window['powerbi-client'].models.LayoutType.MobilePortrait};
    report.updateSettings(settings).then(() => {document.isMobilePortrait = !document.isMobilePortrait;});
}

View solution in original post

2 REPLIES 2
andyparkerson
Advocate I
Advocate I

I figured this out. At load, you can look at the configuration settings, which are stored in the report object.

let report = powerbi.get(document.getElementbyId('embed-container'));
let models = window['powerbi-client'].models;
let isMobile = report.config.settings.layoutType == models.LayoutType.MobilePortrait;

 The variable isMobile is a boolean that shows you if the report is mobile or not.

 

Caution: If you change the layout to MobilePortrait with the report.updateSettings() function, this will no longer work. You could keep track of that in the document at each toggle.

function toggleMobile() {
    let settings = document.isMobilePortrait ? {layoutType:window['powerbi-client'].models.LayoutType.MobileLandscape} : {layoutType:window['powerbi-client'].models.LayoutType.MobilePortrait};
    report.updateSettings(settings).then(() => {document.isMobilePortrait = !document.isMobilePortrait;});
}

HI,@andyparkerson 
We are delighted that you have found a solution and are willing to share it.

 

Accepting your post as the solution is incredibly helpful to our community, as it enables members with similar issues to find answers more quickly.

 

Thank you for your valuable contribution to the community, and we wish you all the best in your work.

 

Best Regards,

Leroy Lu

Helpful resources

Announcements
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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Feb2025 NL Carousel

Fabric Community Update - February 2025

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