Work with 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: Sidebar. Collapse/expand
Toggling Sidebar
You can collapse and expand a sidebar with the help of the toggle() method as easy as that:
sidebar.toggle();
Related sample: Sidebar. Toggle
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
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: Sidebar. Show/hide
Starting from v7.0, it is possible to hide/show all Sidebar controls on the page at once by using the methods without parameters:
// hides all Sidebar controls
sidebar.hide();
// shows all Sidebar controls
sidebar.show();
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: Sidebar. Enable/disable
Starting from v7.0, it is possible to disable/enable all Sidebar controls on the page at once by using the methods without parameters:
// disables all Sidebar controls
sidebar.disable();
// enables all Sidebar controls
sidebar.enable();
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, number) an id of a sidebar item |
sidebar.isDisabled("1"); // -> true/false
Related sample: Sidebar. Enable/disable
Selecting/Unselecting an item
Selecting a Sidebar item
To select a particular Sidebar item, make use of the select() method of Sidebar. The method takes two parameters:
id | (string, number) the id of an item |
unselect | (boolean) optional, true - to unselect previously selected items, otherwise - false; true by default |
sidebar.select("categoryPost");
Related sample: Sidebar. Select / unselect
Unselecting a Sidebar item
To remove selection from a selected item, apply the unselect() method of Sidebar. The method may take the id of an item as a parameter:
// unselects a specified selected item
sidebar.unselect("categoryPost");
It is also possible to remove selection from all previously selected items of Sidebar via the unselect() method:
// unselects all previously selected items
sidebar.unselect();
Related sample: Sidebar. Select / unselect
Checking if a Sidebar item is selected
To check if an item of Sidebar is selected, call the isSelected() method. The method takes one parameter:
id | (string, number) an id of a sidebar item |
sidebar.isSelected("categoryPost"); // -> returns true/false
Related sample: Sidebar. Select / unselect
Getting selected items
To get the selected items, call the getSelected() method. The method returns an array of IDs of selected items:
sidebar.getSelected(); // -> ["selected_1", "selected_1.1"]
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:"navItem", value:"Music"
});
sidebar.data.add({
type:"separator"
});
sidebar.data.add({
type:"menuItem", value:"Photos"
});
Related sample: Sidebar. Data add
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"
});
Related sample: Sidebar. Data update
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");
Related sample: Sidebar. Data remove
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.