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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Ameb
Helper I
Helper I

Typescript API: switchMode

On powebi-models there is a enum defined as viewMode, which is used in the definition of switchMode. But the implementation is inconsistent

 

 

  /**
   * Switch Report view mode.
   *
   * @returns {Promise<void>}
   */
  switchMode(viewMode: models.ViewMode): Promise<void> {
    let url = '/report/switchMode/' + viewMode;
    return this.service.hpm.post<models.IError[]>(url, null, { uid: this.config.uniqueId }, this.iframe.contentWindow)
      .then(response => {
        return response.body;
      })
      .catch(response => {
        throw response.body;
      });
  }

 

 

As viewMode is an enum, this expression translates into 

/report/switchMode/0 or /report/switchMode/1

 

It makes no sense since the API endpoint expects 'view' or 'edit', as seen in the code examples:

 

 

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

    // Get a reference to the embedded report.
    report = powerbi.get(embedContainer);

    // Switch to edit mode.
    report.switchMode("edit");
}

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

    // Get a reference to the embedded report.
    report = powerbi.get(embedContainer);

    // Switch to view mode.
    report.switchMode("view");
} 

 

So either the type definitions or the implementation should be fixed.

2 REPLIES 2
alihm
Power BI Team
Power BI Team

This is fixed.

swithcMode now takes an enum or a string.

Report.switchMode(viewMode: string | ViewMode)

Ameb
Helper I
Helper I

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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