Work with Tabbar
DHTMLX Tabbar inherits its API from DHTMLX Layout, so you can manage Tabbar with Layout methods.
Add and remove tabs
Use the addTab() and removeTab() methods to add and remove tabs.
The addTab() method takes two parameters:
view | (object) an object of a tab. It may include the following properties:
|
index | (number) the position to add a tab into |
// adding a new tab
tabbar.addTab({tab: "tab-" + nextTab++, css:"panel flex"}, 0);
Related sample: Tabbar. Add / remove tab
The removeTab() method takes the id of the tab to remove as a parameter. Call the getId() method to get the id of a tab:
// removing a tab
const id = tabbar.getId(0);
tabbar.removeTab(id);
Related sample: Tabbar. Add / remove tab
Get the id of a tab
The getId() method returns the id of a tab. It takes the index of the tab as a parameter:
const id = tabbar.getId(0);
Iterate over cells
The forEach() method iterates over the cells of Tabbar. Tabbar calls the passed callback function for each cell with the following parameters:
cell— the object of a cellindex— the index of a cellarray— an array with the cells
tabbar.forEach((cell, index, array) => {
console.log(index, cell.id);
});
Set and get the active tab
The setActive() method sets the active tab. It takes the id of a tab as a parameter:
const tabbar = new dhx.Tabbar("tabbar_container", {
mode: "top",
views:[
{ id: "1", tab: "tab-1", css:"panel flex"},
{ id: "2", tab: "tab-2", css:"panel flex"},
{ id: "3", tab: "tab-3", css:"panel flex"},
{ id: "4", tab: "tab-4", css:"panel flex"}
]
});
tabbar.setActive("2");
Related sample: Tabbar. Set active
The getActive() method returns the id of the active tab:
const tabbar = new dhx.Tabbar("tabbar_container", {
mode: "top",
views:[
{ id: "1", tab: "tab-1", css:"panel flex"},
{ id: "2", tab: "tab-2", css:"panel flex"},
{ id: "3", tab: "tab-3", css:"panel flex"},
{ id: "4", tab: "tab-4", css:"panel flex"}
]
});
const active = tabbar.getActive(); // -> "2"
Related sample: Tabbar. Get active
Enable and disable a tab
The enableTab() method enables a tab:
tabbar.enableTab("London");
To disable a tab, use the disableTab() method:
tabbar.disableTab("London");
// -> true|false
Related sample: Tabbar. Disable tab
Check if a tab is disabled
The isDisabled() method checks whether a tab is disabled. It takes the id of the tab as a parameter:
tabbar.isDisabled("London"); // -> returns true/false
To check whether the active tab is disabled, call the isDisabled() method without parameters:
tabbar.isDisabled(); // -> returns true/false
Related sample: Tabbar. Is disabled tab
Attach a component to a cell
Call the attach() method of a Tabbar cell to attach a DHTMLX component to the cell:
const dataview = new dhx.DataView(null, {
template: dataviewTemplate,
itemsInRow: 3,
gap: "10px"
});
dataview.data.parse(dataset);
tabbar.getCell("dataview").attach(dataview);
Related sample: Tabbar. Attach widget
You can't attach Message, Popup, or Window to a Tabbar cell: these components can't have a parent container.
Attach HTML content to a cell
Call the attachHTML() method of a Tabbar cell to attach HTML content to the cell. The method takes a string with HTML as a parameter.
const tabbar = new dhx.Tabbar("tabbar_container", {
mode: "top",
css: "dhx_widget--bordered",
views: [
{ id: "vilnius", tab: "Vilnius" },
]
});
tabbar.getCell("vilnius").attachHTML("<p>Information about Vilnius</p>");