Reverting to the Original View through the JavaScript API

An interesting use case came in from a customer today, asking about something that is hinted at in the documentation of the JavaScript API, but not fully spelled out. They wanted to know how to replicate the ‘Original View’ button in the toolbar. After a bit of testing, I found out something new and not particularly well documented.

The Workbook class of the JS API has the methods for working with the CustomViews, to know which exist, to choose one, or to save a new one. All good — but how to do you interact with the ‘Original View’?

You can do Workbook.getCustomViewsAsync() to an Array of CustomView objects, which have properties which you can use to load any particular one. But interestingly, the ‘Original View’ does not come through in this array; if there are no custom views, the array is empty, and the ‘Original View’ does not appear even after some custom views have been created.

The setCustomViewAsync() method takes a string Name parameter, which will make the workbook switch to the custom view with that name (You can get this name using the getName() method of any CustomView object). However, passing the string ‘Original View’ does not work; you will get an error.

After some testing, I found that if you use the setCustomViewAsync() method without passing any parameter for name, it reverts back to the Original View. I realize this is not clear at all from the documentation, but I’ve tested it out and it appears to work. So reverting back to the Original View is as simple as:


book = viz.getWorkbook();

book.setCustomViewAsync().then( function (e) { // do whatever...});

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s