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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
sccrgoalie1
New Member

PowerBI Javascript API switchMode

I'm working with the latest release (2.5.0) of the PowerBI JavaScript API and am not able to get the report.switchMode method to succeed. An error is always returned with invalid view mode.

I'm calling this after the this.report has been initialized. I've tried sending in a string for the view mode, to see if it worked like that, but that did not work either.

 

this.report.switchModel(models.ViewMode.Edit)

In debugging, I can see it's making the following call but I can't figure out what is an acceptable view mode parameter.

 

'/report/switchMode/' + models.ViewMode.Edit

 

1 ACCEPTED SOLUTION
v-micsh-msft
Microsoft Employee
Microsoft Employee

Hi,

 

Please take a try with the way below:

You can use the following JavaScript to switch into view mode, if you are in edit mode

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

You can use the following JavaScript to switch into edit mode, if you are in view mode

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

For more configuration code, check:

Embed Configuration Details

 

Regards,

Michael

 

View solution in original post

2 REPLIES 2
v-micsh-msft
Microsoft Employee
Microsoft Employee

Hi,

 

Please take a try with the way below:

You can use the following JavaScript to switch into view mode, if you are in edit mode

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

You can use the following JavaScript to switch into edit mode, if you are in view mode

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

For more configuration code, check:

Embed Configuration Details

 

Regards,

Michael

 

Thanks Michael.  This works. The current TypeScript definitions require a models.ViewMode enum value, but if I bypass the TypeScript def and pass in a string as you suggest it works. Looks like the library just needs to be updated so that it sends the string value instead of the numeric value of the enum. 

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors