Customizing the Toolbar
WebDataRocks Toolbar is designed to make your web reporting experience easier and more convenient. You can customize the Toolbar in the following ways:
- Add new custom tabs.
- Remove the tabs you don’t need.
- Reorder/change the existing tabs.
- Set your custom icons for tabs.
Important Before customizing the Toolbar, ensure it is enabled.
Let’s see how to customize the Toolbar in practice.
All customization can be made using the beforetoolbarcreated event which is triggered before the Toolbar is created. The event’s handler will be responsible for changing the Toolbar.
How to remove tabs
Step 1. Assign a handler (e.g., customizeToolbar
) to the beforetoolbarcreated event. The handler function has the toolbar
as a parameter that contains information about the Toolbar.
Step 2. Inside the handler (e.g., customizeToolbar
), retrieve all the tabs using the toolbar.getTabs()
method. It returns an array of objects that describe tabs’ properties.
Step 3. To remove a tab, delete a corresponding object from the array of tabs.
Your code should look similar to the following example:
import * as WebDataRocksReact from "@webdatarocks/react-webdatarocks";
function App() {
function customizeToolbar(toolbar) {
// Get all tabs from the Toolbar
let tabs = toolbar.getTabs();
toolbar.getTabs = function() {
// Delete the Connect tab
tabs = tabs.filter(tab => tab.id !== "wdr-tab-connect");
return tabs;
}
}
return (
<div>
<WebDataRocksReact.Pivot
toolbar={true}
beforetoolbarcreated={customizeToolbar}
/>
</div>
);
}
export default App
How to add new tabs
Step 1. Assign a handler (e.g., customizeToolbar
) to the beforetoolbarcreated event. The handler function has the toolbar
as a parameter that contains information about the Toolbar.
Step 2. Inside the handler (e.g., customizeToolbar
), retrieve all the tabs using the toolbar.getTabs()
method. It returns an array of objects that describe tabs’ properties.
Step 3. Add a new tab to the array of tabs.
Your code should look similar to the following example:
import * as WebDataRocksReact from "@webdatarocks/react-webdatarocks";
function App() {
const customizeToolbar = (toolbar) => {
// Get all tabs from the Toolbar
let tabs = toolbar.getTabs();
toolbar.getTabs = () => {
// Add a new tab
tabs.unshift({
id: "war-tab-new tab",
title: "New Tab",
handler: yourCustomFunction,
icon: toolbar.icons.open,
});
return tabs;
};
};
const yourCustomFunction = () => {
// Your functionality
}
return (
<div>
<WebDataRocksReact.Pivot
toolbar={true}
beforetoolbarcreated={customizeToolbar}
/>
</div>
);
}
export default App
Even more advanced customization
In this guide, we mentioned how to remove the Toolbar tabs and how to add a new one. For further customization, you can reorder the tabs, set the custom icons for the tabs, or implement new functionality. We recommend investigating the existing code to understand how the Toolbar works:
- Open the source code of the Toolbar –
webdatarocks.toolbar.js
file. - Find a prototype of the
toolbar.getTabs()
method. - Investigate how this method works.
You can also change the appearance of the Toolbar by changing the component theme.