Loading websheet objects with the JavaScript library

Use JavaScript to instantiate a websheet object. After the object is loaded, you can then assign it as a descendant of the document body to display it in your web page.

You load a websheet object by using the following format to specify the required properties and optional functions that define the object.

new Workbook({properties ..., functions ...});

The properties include values that specify the login credentials and the websheet object that you want to open.

The functions can include optional code to notify you about onLoad and onTitleDimensionElementChange events for the object.

For more information, see TM1 Web JavaScript library Workbook class.

Example

The following example shows a JavaScript function that loads a websheet object.

The code to instantiate the object must use the specific AMD (Asynchronous Module Definition) syntax and the AMD require keyword. After the object is created, the function assigns it as the child of a document body.


// Load websheet with parameters for adminHost, tm1Server, username and password
function loadWebsheet() {
    require([
        "tm1web/api/Workbook"
    ], function(Workbook){
        var loadedWebsheet = new Workbook({
            adminHost: "localhost",
            tm1Server: "Planning Sample",
            username: "admin",
            password: "apple",
            path: "Applications/Planning Sample/Management Reporting/Actual v Budget",
            onLoad: function() {
                console.debug("Workbook loaded successfully.");
            }
        });

        // Add websheet to the document body
        document.body.appendChild(loadedWebsheet.domNode);

        loadedWebsheet.startup();
    });
};

The following example loads a websheet object by using a session token for the login.


// Load websheet with a session token
function loadWebsheet() {
    require([
        "tm1web/api/Workbook"
    ], function(Workbook){
        var loadedWebsheet = new Workbook({
            sessionToken: "yourSessionToken",
            path: "Applications/Planning Sample/Management Reporting/Actual v Budget",
            onLoad: function() {
                console.debug("Workbook loaded successfully.");
            }
        });
        // Add websheet to the document body
        document.body.appendChild(loadedWebsheet.domNode);

        loadedWebsheet.startup();
    });
};