Need a special offer?Find out if your project fits.
+
  1. API reference
  • Introduction
  • Connecting to Data Source
  • Browser compatibility
  • 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", 
      componentFolder: "node_modules/flexmonster/",
      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", 
      componentFolder: "node_modules/flexmonster/",
      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", 
      componentFolder: "node_modules/flexmonster/",
      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:

    • id is used for CSS styling.
    • title is the tab’s label.
    • handler is a function that handles clicks on this tab.
    • icon is an HTML tag that contains your custom icon for this new tab. You can choose one of the basic vector icons defined in the flexmonster.toolbar.js file.

    See the full list of properties available for Toolbar tabs.

    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, see our guide on changing themes.

    What’s next?

    You may be interested in the following articles: