Work with Sidebar

Hiding and showing controls

You can show or hide controls by their IDs. Pass them to the corresponding methods - show() and hide():

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

Related sample:  Show/hide - DHTMLX Sidebar

Expanding and collapsing Sidebar

It is possible to expand/collapse a sidebar using two corresponding methods - expand() and collapse():

sidebar.expand(); // expands a sidebar
sidebar.collapse(); // collapses a sidebar

Related sample:  Collapse/Expand - DHTMLX Sidebar

Checking if Sidebar is collapsed

To check whether Sidebar is collapsed, make use of the isCollapsed() method of the Sidebar API. The method returns true, if a sidebar is collapsed, and false if it's expanded.

sidebar.isCollapsed(); // -> true/false

Disabling and enabling controls

You can disable or enable controls. The related methods - enable() and disable() - take the IDs of controls as parameters:

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

Related sample:  Enable/disable - DHTMLX Sidebar

Checking if a sidebar item is disabled

To check if an item of Sidebar is disabled, call the isDisabled() method. The method takes one parameter:

  • id - (string) an id of a sidebar item
sidebar.isDisabled("1"); // -> true/false

Related sample:  Enable/disable - DHTMLX Sidebar

Toggling Sidebar

You can collapse and expand a sidebar with the help of the toggle() method as easy as that:

sidebar.toggle();

Related sample:  Toggle - DHTMLX Sidebar

Adding a tooltip to a control

You can attach a tooltip to a control. For this you need to provide the tooltip property with the tooltip text in the control object before the sidebar initialization:

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

Using Tree collection API

You can manipulate the controls of Sidebar with the help of the Tree collection API.

Adding new controls into Sidebar

It is possible to add more controls into the initialized Sidebar on the fly. Use the add() method of Tree Collection. It 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)
sidebar.data.add({
    type:"button", value:"Add"
});
sidebar.data.add({
    type:"separator"
});
sidebar.data.add({
    type:"button", value:"Remove"
});

Templates for Sidebar controls in the JSON format are given here.

Updating config of controls

You can change config options of the control via the update() method of Tree Collection. It takes two parameters:

  • id - the id of the control
  • config - an object with new configuration of the control

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

sidebar.data.update("add", { 
    icon: "icon_name" 
});

Removing controls from Sidebar

To remove a control, make use of the remove() method of Tree Collection. Pass the id of the control that should be removed to the method:

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

Rearranging controls

You can move menu controls to different positions with the move() method of Tree Collection. For example, this is how you can move an item with ID "2" to the left edge of the sidebar:

sidebar.data.move("2",0);


Check the full list of Tree collection API.

Back to top