Get Free Trial
  1. API reference
Connecting to Data Source
Configuring the component
  • Documentation for older versions
  • Table of contents

    Customizing the Toolbar

    About the Toolbar

    The Toolbar is an addition to Flexmonster. It uses a standard Flexmonster API and provides easy access to the most commonly used features. The Toolbar is free and provided “as is”.

    Enabling the Toolbar is very easy, just set the toolbar parameter in the new Flexmonster() function call to true:

    var pivot = new Flexmonster({
    container: "pivotContainer",
    toolbar: true
    });

    Ensure that your flexmonster/ folder includes the toolbar/ folder and that it’s not empty.

    Use flexmonster.toolbar to get a reference to the Toolbar instance. It allows you to call its functions on the page from outside of Flexmonster Pivot.

    Customizing

    The Toolbar can be customized using the beforetoolbarcreated event. Tabs and buttons can be removed from it and new ones can be easily added.

    Below we describe how to perform basic Toolbar customization. See the Examples page for more examples on how to modify the Toolbar.

    Removing a tab from the Toolbar

    Add a beforetoolbarcreated event handler. Inside the handler, you can get all tabs using the getTabs() method. It returns an array of objects, each of which describes a tab.

    To remove a tab, remove the corresponding object from the array using the tab’s id. The following example will remove the Connect tab:

    var pivot = new Flexmonster({
        container: "pivotContainer", 
        toolbar: true, 
        beforetoolbarcreated: customizeToolbar 
    }); 
    
    function customizeToolbar(toolbar) { 
        // get all tabs 
        let tabs = toolbar.getTabs(); 
        toolbar.getTabs = function () {
            // remove the Connect tab using its id
            tabs = tabs.filter(tab => tab.id != "fm-tab-connect");
            return tabs; 
        } 
    } 

    Open the example on JSFiddle.

    Adding a new tab to the Toolbar

    The following code will add a new tab:

    var pivot = new Flexmonster({ 
    container: "pivotContainer",
    toolbar: true,
    beforetoolbarcreated: customizeToolbar
    });

    function customizeToolbar(toolbar) {
    // get all tabs
    var tabs = toolbar.getTabs();
    toolbar.getTabs = function () {
    // add new tab
    tabs.unshift({
    id: "fm-tab-newtab",
    title: "New Tab",
    handler: newtabHandler,
    icon: this.icons.open
    });
    return tabs;
    }
    var newtabHandler = function() {
    // add new functionality
    }
    }

    where:

    • title – String. The tab’s label.
    • id – String. The id used in CSS styles.
    • handler – Function. The function that handles clicks on this tab.
    • icon – String. The HTML tag containing your custom icon for this new tab. You can choose one of the basic vector icons defined in the flexmonster.toolbar.js file.

    There are also some optional parameters:

    • args – Any. Arguments to pass to the handler.
    • menu – Array. Dropdown menu items.
    • mobile – Boolean. When set to false, the tab does not show on mobile devices. Default value: true.
    • ios – Boolean. When set to false, the tab does not show on iOS devices. Default value: true.
    • android – Boolean. When set to false false, the tab does not show on Android devices. Default value: true.
    • rightGroup – Boolean. When set to true, the tab is positioned on the right side of the Toolbar. Default value: false.

    Check out an example of creating a new tab on JSFiddle.

    Further customization

    You can customize almost everything. To explore all the options, we recommend investigating the existing code. Look in the toolbar/ folder (you can find it in [package]/flexmonster/). Open the flexmonster.toolbar.js file. Find the tab section (it starts with the getTabs() function expression) to understand how it works.

    To change the appearance of the Toolbar, read customizing appearance.

    What’s next?

    You may be interested in the following articles: