Add a custom tab to the Toolbar

Customizing the Toolbar

HTML

<link rel="stylesheet" href="https://s3.amazonaws.com/flexmonster/2.3/demo.css">
<script src="https://cdn.flexmonster.com/flexmonster.js"></script>

<div>
  <h2>How to add a custom tab to the Toolbar</h2>
  <p>
  You can add a new tab to the Toolbar using the <code>beforetoolbarcreated</code> event. In the event handler, define a custom tab with a needed functionality and add it to the array of Toolbar tabs. We've added the <strong>New Tab</strong> in this example.</p>
  <p>With the <code>beforetoolbarcreated</code> event, you can also remove or update existing Toolbar tabs. <a href="https://www.flexmonster.com/doc/customizing-toolbar/" target="_blank">Refer to our docs to learn more about the Toolbar customization</a>.
  </p>
</div>

<div id="pivot-container"></div>

CSS

h2 {
  text-align: center;
}

 

a {
  color: #00a45a;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

JavaScript

let pivot = new Flexmonster({
  container: "pivot-container",
  componentFolder: "https://cdn.flexmonster.com/",
  height: 400,
  toolbar: true,
  beforetoolbarcreated: customizeToolbar,
  report: {
    dataSource: {
      filename: "data/data.json"
    }
  }
});

function customizeToolbar(toolbar) {
  let tabs = toolbar.getTabs();
  toolbar.getTabs = function() {
    tabs = tabs.filter(tab => tab.id != "fm-tab-connect");
        tabs = tabs.filter(tab => tab.id != "fm-tab-open");
        tabs = tabs.filter(tab  => tab.id != "fm-tab-save");
        tabs = tabs.filter(tab  => tab.id != "fm-tab-export");
        tabs = tabs.filter(tab  => tab.id != "fm-tab-grid");
        tabs = tabs.filter(tab  => tab.id != "fm-tab-charts");
    tabs.unshift({
      id: "fm-tab-newtab",
      title: "New Tab",
      handler: newtabHandler,
     
     
    });
     tabs.push({
      id: "2",
      title: "ssasasa",
      handler: newtabHandler,
      
    });
    return tabs;
  }

  let newtabHandler = () => {
    alert("New functionality!");
  }
}