Configuration of a Cell
Each cell of a layout takes a configuration object that defines what the cell shows and how it behaves. The properties of this object set the content and the header of a cell, its size and borders, and whether the cell is collapsible, resizable, or hidden. The sections below describe these settings. For the full list of properties, see the Cell API overview.
HTML content
Use the html property to set HTML content for a cell:
const layout = new dhx.Layout("layout_container", {
cols: [
{ header: "Cell header", html: "Hello world"}
]
});
Related sample: Layout. HTML content
Cell header
Each layout cell can have a header with text that describes the cell content. Set the text in the header property:
const layout = new dhx.Layout("layout_container", {
cols: [
{ header: "Perfect cell header"}
]
});
To add an icon or an image to the header, use the headerIcon or headerImage property:
const layout = new dhx.Layout("layout_container", {
cols: [
{ header: "Cell header", headerIcon: "dxi dxi-check" }
]
});
// or
const layout = new dhx.Layout("layout_container", {
cols: [
{ header: "Cell header", headerImage:"/img.png"}
]
});
Related sample: Layout. Header
Height of a cell header
Use the headerHeight property to set the height of a cell header:
const layout = new dhx.Layout("layout_container", {
rows: [
{
id: "row1"
},
{
id: "row2",
header: "Row 2",
headerHeight: 80
}
]
});
Related sample: Layout. Header
If you don't set the header property of a cell, the headerHeight property adds a header without text to the cell.
Custom content in a cell header

Besides text, the header of a cell can contain HTML markup or a DHTMLX widget. To add custom content, set the header property to a callback function. While rendering the cell, Layout calls the function with the configuration object of the cell and places the returned content into the header.
The type of the value that you set for the header property defines the expected behavior:
- A string: the header shows the string as plain text. Layout doesn't interpret HTML tags and displays them as part of the text
- A callback function: tells Layout that the header supports HTML content
A cell with a custom header collapses and expands like any other cell. See the Collapsibility section.
HTML markup in a header
The callback can return a string with HTML tags. The header renders this string as HTML markup:
const layout = new dhx.Layout("layout_container", {
cols: [
{
id: "orders",
header: cell => `<b>Orders</b> <i>3 new</i>`
}
]
});
Related sample: Layout. Cell header with HTML template
A DHTMLX widget in a header
The callback can also return an initialized widget, the same object that you pass to the attach() method of a cell. A component name doesn't work here because the header treats any returned string as HTML:
const toolbar = new dhx.Toolbar(null, {
data: [
{ id: "add", type: "button", value: "Add", icon: "dxi dxi-plus" },
{ id: "remove", type: "button", value: "Remove", icon: "dxi dxi-delete" }
]
});
const layout = new dhx.Layout("layout_container", {
cols: [
{ header: () => toolbar }
]
});
Related samples:
Icon, image and height of a custom header
The headerIcon and headerImage options work with a custom header as well. The cell renders the icon and the image before the content that the callback returns.
The height of a header adjusts to the size of the custom content. To use a fixed height, set the headerHeight option.
Events of the header content
Use the on property of the cell to handle clicks and other DOM events in the markup that the callback returns. In the property, specify the selector of the target element.
The example below shows how to make a control inside a custom cell header interactive. The header callback returns markup with a "Check now" button, and a click on that button rebuilds the content of the cell:
// builds the HTML content of the cell
function metrics() {
return `<div>Checked at ${new Date().toLocaleTimeString()}</div>`;
}
const layout = new dhx.Layout("layout_container", {
rows: [
{
id: "service",
html: metrics(),
header: () => `<span>API service</span>
<button type="button">Check now</button>`,
on: {
click: {
"button": function() {
layout.getCell("service").attachHTML(metrics());
}
}
}
}
]
});
The attachHTML() call repaints the cell, so Layout calls the header callback again and renders the header with the current data as well.
Related sample: Layout. Cell header with HTML template
Cell size
Use the width and height properties to set the size of a cell:
const layout = new dhx.Layout("layout_container", {
rows: [
{
cols: [
{
header: "Block 1",
width: "40%"
},
{
header: "Block 2",
width: "60%"
}
]
},
{
rows: [
{
header: "Block 3",
height: "200px"
},
{
header: "Block 4",
height: "300px"
}
]
}
]
});
From v7.0, you can set the minimum and maximum sizes of a cell with the maxHeight, maxWidth, minHeight, and minWidth properties:
const layout = new dhx.Layout("layout_container", {
cols: [
{
header: "Cell header",
minWidth: "400px",
maxWidth: "600px",
minHeight: "40px",
maxHeight: "100px"
}
]
});
The minWidth and maxWidth properties limit the width of a cell: the width can't be less than minWidth or greater than maxWidth. The minHeight and maxHeight properties limit the height in the same way.
const layout = new dhx.Layout("layout_container", {
cols: [
{
header: "Cell header",
width: "50%",
maxWidth: "200px"
}
]
});
In this example, the cell takes 50% of the parent container width but is never wider than 200px.
Autosize for cells
From v7.0, a cell can adjust its width or height to the size of its content. Set the width or height property to "content":
const layout = new dhx.Layout("layout_container", {
cols: [
{
header: "Cell header",
width: "content"
},
// more options
]
});
Resizability
Set the resizable property to true to let users resize a cell:
const layout = new dhx.Layout("layout_container", {
cols: [
{ header: "Cell header", resizable:true}
]
});
Related sample: Layout. Collapsable and resizable
Hidden cell
Set the hidden property to true to render a layout with hidden cells:
const layout = new dhx.Layout("layout_container", {
cols: [
{ header: "Cell header", hidden:true}
]
});
Collapsibility
Two properties of a cell control collapsing:
collapsable— defines whether users can collapse and expand the cellcollapsed— defines whether the cell is collapsed when the layout initializes
const layout = new dhx.Layout("layout_container", {
cols: [
{ header: "Cell header", collapsable:true, collapsed:false}
]
});
A collapsable cell keeps its collapse/expand icon when the header contains custom content. A click on the custom content itself calls no API of the cell, so buttons and other controls inside the header remain operable. A user collapses and expands the cell by clicking the collapse icon or the free space of the header.
Related samples:
Progress bar
A Layout cell can show a progress bar (a loading spinner) while the cell has no attached component or HTML content. To enable the progress bar, set the progressDefault property of the cell to true:
const layout = new dhx.Layout("layout_container", {
type: "line",
rows: [
{
id: "one",
header: "Header",
height: "250px",
resizable: true,
progressDefault: true
},
{
id: "two",
height: "250px",
progressDefault: true,
},
]
});
As soon as you attach a component or HTML content to the cell, the cell hides the progress bar.
The default value of the progressDefault property is false.
Borders between cells
The default layout has no borders or space between cells, so the cells look merged. From v7.0, you can add borders or space between cells with the type configuration property:
const layout = new dhx.Layout("layout_container", {
type: "space",
cols: [
{
html: "1"
},
{
html: "2"
},
{
html: "3"
}
]
});
Related sample: Layout. Types: space, wide, line, none
Related sample: Layout. Types in a complex layout
The option takes the following values: "line", "wide", "space", and "none".
| type:"line" | type:"wide" | type:"space" | type:"none" |
|---|---|---|---|