Skip to main content

NavItem

The NavItem control is the default control of navigation-related components. It can contain other controls as nested items.

Toolbar navItem with an icon, NAV ITEM label, and a number badge in DHTMLX Suite

Related sample: Toolbar. NavItem

Add NavItem​

Use the add() method of TreeCollection to add a NavItem control to a toolbar:

toolbar.data.add({
type:"navItem", value:"My NavItem"
});

Properties​

Check the list of properties that you can set in the configuration object of a NavItem control.

Add an icon​

Use the icon property to add an icon to a NavItem control:

{
type:"navItem", value:"Some",
icon:"dxi dxi-check"
}

Add a badge with a number​

Use the count property to add a badge with a number to a NavItem control, for example, to count new messages:

{
type:"navItem", value:"Some",
icon:"dxi dxi-check",
count:10
}

Add HTML content​

Use the html property to add custom HTML content to a NavItem control:

{
type: "navItem",
html: "<div className='user-button'><img src='../avatars/Avatar.jpg'/></div>",
}

Related sample: Toolbar. Item HTML content

Show and hide a NavItem​

The show() and hide() methods of Toolbar show and hide a NavItem control by its ID:

toolbar.show(id);
toolbar.hide(id);

Related sample: Toolbar. Hide / show items

Enable and disable a NavItem​

The enable() and disable() methods of Toolbar enable and disable a NavItem control by its ID:

toolbar.enable(id);
toolbar.disable(id);

Related sample: Toolbar. Enable / disable items

Add a tooltip​

Use the tooltip property to add a tooltip to a NavItem control:

{
type:"navItem",
value:"Click",
tooltip:"Click me and find out why"
}

Related sample: Toolbar. Tooltips

Two-state NavItems​

Set the twoState property to create a NavItem with two states: active (pressed) and inactive (unpressed). The active property sets the initial state:

{
type: "navItem",
icon: "dxi dxi-format-bold",
tooltip: "bold text",
twoState: true, active: false
}

Related sample: Toolbar. TwoState

Change the state of a two-state NavItem​

The setState() method of Toolbar changes the state of a two-state NavItem:

{
type: "navItem", icon: "dxi dxi-format-bold",
tooltip: "bold text", twoState: true,
id:"bold"
}
...
toolbar.setState({"bold":true}); // active:true
// or
toolbar.setState({"bold":false}); // active:false

The setState() method takes one parameter: a key-value pair with the ID of the item and the new value.

Get the state of a two-state NavItem​

The getState() method returns the current state of a two-state NavItem:

{
type: "navItem", icon: "dxi dxi-format-bold",
tooltip: "bold text", twoState: true,
id:"bold"
}
...
const state = toolbar.getState(); // -> { bold:true } or { bold:false }