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 (lines 14-24 in the JavaScript box).</p>
  <p>With the <code>beforetoolbarcreated</code> event, you can also remove or update existing Toolbar tabs. 
  </p>
  <p>
  <a href="https://www.flexmonster.com/doc/customizing-toolbar/" target="_blank">Refer to our docs to learn more about customizing the Toolbar</a>.
  </p>
</div>

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

CSS

h2 {
  text-align: center;
}

p {
  font-size: 15px;
  line-height: 1.5;
  padding-right: 10px;
  padding-left: 10px;
}

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

a:hover {
  text-decoration: underline;
}

code {
  font-size: 105%;
  color: #DF3800;
  background-color: #f5f5f5;
  padding: 1px 4px;
  font-family: monospace !important;
  border-radius: 4px;
}

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.unshift({
      id: "fm-tab-newtab",
      title: "New Tab",
      handler: newtabHandler,
      icon: this.icons.open
    });
    console.log(tabs);
    const export_tab = tabs[4];
    const current_menu = export_tab.menu;
    export_tab.menu = [{
      id: "custom",
      title: "Custom",
      icon: "",
      menu: current_menu
    }]
    return tabs;
  }

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