microsoft / powerbi-client-angular

Power BI Angular component. This library lets you embed Power BI report, dashboard, dashboard tile, report visual, or Q&A in your Angular application.
Other
134 stars 63 forks source link

Unexpected results with LayoutSwitch #55

Closed k0nsun closed 2 months ago

k0nsun commented 9 months ago

When we use the "LayoutSwitch" function, the landscape view does not always work.

The settings used:

this.reportConfig = {
        ...this.reportConfig,
        id: reportConfigResponse.Id,
        embedUrl: reportConfigResponse.EmbedUrl,
        accessToken: reportConfigResponse.EmbedToken.Token,
        settings: {
                        panes: {
                            filters: {
                                expanded: false,
                                visible: false,
                            },
                        },
                        layoutType: models.LayoutType.MobilePortrait
                    }
    };

Here the code to change the layout (simplify):

  @HostListener('window:orientationchange', ['$event'])
  onOrientationChange(event: any) {
    if (event.target.screen.orientation.angle === 90) {
        console.debug('MobilePortrait');
        this.reportObj.getReport().switchLayout(models.LayoutType.MobilePortrait);

    }
    else {
        console.debug('MobileLandscape');
        this.reportObj.getReport().switchLayout(models.LayoutType.MobileLandscape);
    }    
  }

Small details:

Do you have any work-around to make it work as it is supposed to? Thanks in advance. Bug_Landscape_Portrait.zip

v-MadhavC commented 2 months ago

It is not supported to switch the layout from MobilePortrait to MobileLandscape, you need to first call powerbi.reset() to remove the iframe and then use powerbi.embed() with the same container.

For more information, refer to this documentation: Embedding a Power BI report with mobile layout in Power BI embedded analytics | Microsoft Learn