Skip to main content

Work with Toolbar

Set and get values and states​

Set values and states​

The setState() method changes the value of a control or the state of a TwoState navItem. The method takes one parameter: a key-value pair with the ID of the control and its new value or state.

The following example changes the state of a TwoState navItem:

{type:"navItem", twoState:true, id:"check"}
...
toolbar.setState({"check":true});
//or
toolbar.setState({"check":false});

The following example changes the value of an input:

{type:"input", id:"name", value:""}
...
toolbar.setState({"name":"Maintenance"});

Related sample: Toolbar. Set state

Get values and states​

The getState() method returns the current value or state of a control.

Starting from v7.0, the method takes the ID of a Toolbar control as an optional parameter and returns the value or state of this control. If you omit the id parameter, the method returns an object with the IDs of all controls and their values or states.

The method returns the following values for a TwoState navItem:

{type:"navItem", twoState:true, id:"check"}
...
toolbar.getState("check"); // -> true/false
// or
toolbar.getState(); // -> { "check":true } or { "check":false }

The method returns the following values for an input:

{type:"input", id:"name", value:"Maintenance"}
...
toolbar.getState("name"); // -> "Maintenance"
// or
toolbar.getState(); // -> {"name":"Maintenance"}

Related sample: Toolbar. Get state

Show and hide controls​

The show() and hide() methods show and hide controls by their IDs:

toolbar.hide(id); // hides a control
toolbar.show(id); // shows a control

Related sample: Toolbar. Hide / show items

Starting from v7.0, you can call the methods without parameters to hide or show all Toolbar controls at once:

// hides all Toolbar controls
toolbar.hide();
// shows all Toolbar controls
toolbar.show();

Enable and disable controls​

The enable() and disable() methods enable and disable controls by their IDs:

toolbar.disable(id); // disables a control
toolbar.enable(id); // enables a control

Related sample: Toolbar. Enable / disable items

Starting from v7.0, you can call the methods without parameters to disable or enable all Toolbar controls at once:

// disables all Toolbar controls
toolbar.disable();
// enables all Toolbar controls
toolbar.enable();

Check if a Toolbar item is disabled​

The isDisabled() method checks whether a Toolbar item is disabled. The method takes one parameter:

id(string | number) the ID of a Toolbar item

menu.isDisabled("1"); // -> true/false

Related sample: Toolbar. Enable / disable items

Add a tooltip to a control​

You can attach a tooltip to a control. Specify the tooltip text in the tooltip property of the control before you initialize the toolbar:

{
type: "text",
value: "test1",
tooltip: "tooltip for test1"
}

Select and unselect an item​

Select a Toolbar item​

The select() method of Toolbar selects a particular item. The method takes two parameters:

id(string | number) the ID of an item
unselect(boolean) optional, true to unselect previously selected items, otherwise false (default: true)
toolbar.select("web");

Related sample: Toolbar. Select / unselect items

Unselect a Toolbar item​

The unselect() method of Toolbar removes selection from a selected item. The method takes the ID of an item as an optional parameter:

// unselects a specified selected item
toolbar.unselect("web");

Call the method without parameters to remove selection from all selected Toolbar items:

// unselects all previously selected items
toolbar.unselect();

Related sample: Toolbar. Select / unselect items

Check if a Toolbar item is selected​

The isSelected() method checks whether a Toolbar item is selected. The method takes one parameter:

id(string | number) the ID of a Toolbar item

toolbar.isSelected("web"); // -> returns true/false

Related sample: Toolbar. Select / unselect items

Get selected items​

The getSelected() method returns an array with the IDs of selected items:

toolbar.getSelected(); // -> ["selected_1", "selected_1.1"]

Related sample: Toolbar. Tooltips

Use the TreeCollection API​

You can manipulate Toolbar controls with the TreeCollection API.

Add new controls to Toolbar​

Use the add() method of TreeCollection to add controls to an initialized toolbar. The method takes three parameters:

config(object) the configuration object of the added control
index(number) optional, the position to add a control at
parent(string) optional, the ID of a parent control (for the menuItem control type)

toolbar.data.add({
type:"button", value:"Add"
});
toolbar.data.add({
type:"separator"
});
toolbar.data.add({
type:"button", value:"Remove"
});

Related sample: Toolbar. Add new item

Check the JSON format templates for Toolbar controls.

Update the configuration of controls​

The update() method of TreeCollection changes the configuration options of a control. The method takes two parameters:

idthe ID of a control
configan object with the new configuration of the control

For example, you can change the icon of a control:

toolbar.data.update("edit", { 
icon: "mdi mdi-pencil"
});

Related sample: Toolbar. Update item

Remove controls from Toolbar​

The remove() method of TreeCollection removes a control. Pass the ID of the control to the method:

toolbar.data.remove("control-id");

Related sample: Toolbar. Remove item

Rearrange controls​

Use the move() method of TreeCollection to move Toolbar controls to different positions. For example, the following code moves the item with the "2" ID to the left edge of the toolbar:

toolbar.data.move("2",0);
note

Check the full TreeCollection API reference.