Work with Layout
Remove cells
The removeCell() method removes a cell from a layout. The method takes the id of the cell as a parameter:
layout.removeCell(id);
Related sample: Layout. Remove cell
Iterate over cells
The forEach() method iterates over the cells of Layout. Layout 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
layout.forEach((cell, index, array) => {
console.log(index, cell.id);
});
If you pass only the callback, the method starts from the root cell and visits each nested level. To limit the iteration, pass the id of the parent cell as the second parameter and the number of levels as the third parameter:
layout.forEach((cell, index, array) => {
console.log(index, cell.id);
}, parentID, level);
Related sample: Layout. ForEach
Get the object of a cell
The getCell() method returns the object of a cell by its id:
layout.getCell("header");
Attach and detach a component
Attach a component
Call the attach() method of a Layout cell to attach a DHTMLX component to the cell:
const layout = new dhx.Layout("layout_container", {
width:"400px", height:"600px"
});
const list = new dhx.List(null, {
template: listTemplate,
itemHeight: 52,
height: "100%",
dragMode: "both"
});
list.data.load('../common/library.json');
layout.getCell("list").attach(list);
Related sample: Layout. Attach widget
You can't attach Message, Popup, or Window to a Layout cell: these components can't have a parent container.
Detach a component
The detach() method of a cell detaches a component from the cell:
layout.getCell("list").detach();
Attach and detach HTML content
Attach HTML content
Call the attachHTML() method of a Layout cell to attach HTML content to the cell. The method takes a string with HTML as a parameter:
const layout = new dhx.Layout("layout_container", {
width:"400px", height:"600px"
});
const html = "<p>Hello world</p>";
layout.getCell("content").attachHTML(html);
Detach HTML content
The detach() method of a cell detaches HTML content from the cell:
layout.getCell("content").detach();
Hide and show a cell
Use the hide() and show() methods of a cell to hide and show the cell:
// hiding a cell
layout.getCell("toolbar").hide();
Related sample: Layout. Hide
// showing a cell
layout.getCell("toolbar").show();
Related sample: Layout. Show
Check if a cell is visible
You can hide a cell, for example, with the hidden property. The isVisible() method checks whether a cell is visible. It returns true if the cell is visible and false if it is hidden:
layout.getCell("sidebar").isVisible(); // -> true|false
Collapse and expand a cell
Use the collapse() and expand() methods of a cell to collapse and expand the cell:
// collapsing a cell by its id
layout.getCell("sidebar").collapse();
// expanding a cell by its id
layout.getCell("sidebar").expand();
Related sample: Layout. Expand / collapse
Toggle a cell
The toggle() method of a cell collapses an expanded cell and expands a collapsed one:
layout.getCell("toolbar").toggle();
Related sample: Layout. Toggle
Show and hide a progress bar
A progress bar shows users that the content is loading or updating. You can show and hide the progress bar in the Layout container or in a separate cell.
A cell can also show the progress bar automatically while it has no attached component or HTML content. See Progress bar in the cell configuration guide.
Progress bar in the Layout container
The progressShow() method of Layout shows the progress bar in the Layout container:
layout.progressShow();
To hide the progress bar, call the progressHide() method:
layout.progressHide();
Progress bar in a Layout cell
The progressShow() method of a cell shows the progress bar in this cell:
layout.getCell("two").progressShow();
To hide the progress bar, call the progressHide() method of the cell:
layout.getCell("two").progressHide();
Related sample: Layout. Spinner (busy indicator/ progress bar) for Layout and its cells