diff --git a/docs/layout/api/cell/layout_cell_header_config.md b/docs/layout/api/cell/layout_cell_header_config.md index ca44dd1c..f9711791 100644 --- a/docs/layout/api/cell/layout_cell_header_config.md +++ b/docs/layout/api/cell/layout_cell_header_config.md @@ -6,21 +6,95 @@ description: You can explore the header config of Layout in the documentation of # header -@short: Optional. Adds a header with text for a cell +@short: Optional. Adds a header with a text or with custom content for a cell -@signature: {'header?: string;'} +#### Usage + +~~~ts +type TCellHeaderTemplate = (cell: ICellConfig) => string | IView; + +header?: string | TCellHeaderTemplate; +~~~ + +The type of the value defines the way the component renders the content of a header: + +- **a string** - defines the text the header shows. The component doesn't interpret HTML tags and displays them as a part of the text +- **a callback function** - defines the way to render HTML content in a header. It takes the following parameter: + + - `cell: ICellConfig` - the configuration object of the cell the header belongs to + + The component calls the callback while it renders the cell and places the returned value into the DOM of the header: + + - *a string with HTML markup* - the component parses the markup and renders it + - *an object of a DHTMLX widget* - an initialized widget, the same object that you pass to the [`attach()`](layout/api/cell/layout_cell_attach_method.md) method of a cell. The name of a component doesn't work here, as the header treats any returned string as HTML + +#### Example + +- a header with a text + +~~~jsx +const layout = new dhx.Layout("layout_container", { + cols: [ + { header: "Cell header" } + ] +}); +~~~ + +- a header with HTML content + +~~~jsx +const layout = new dhx.Layout("layout_container", { + cols: [ + { + id: "orders", + header: cell => `Orders 3 new` + } + ] +}); +~~~ + +- a header with a DHTMLX widget inside + +~~~jsx +const toolbar = new dhx.Toolbar(null, { + data: [ + { id: "add", type: "button", value: "Add", icon: "dxi dxi-plus" } + ] +}); -@example: const layout = new dhx.Layout("layout_container", { cols: [ - { header: "Cell header"} + { header: () => toolbar } ] }); +~~~ @descr: -**Related sample**: [Layout. Header](https://snippet.dhtmlx.com/bxqnzesl) -[comment]: # (@relatedapi: layout/api/cell/layout_cell_headerheight_config.md layout/api/cell/layout_cell_headericon_config.md layout/api/cell/layout_cell_headerimage_config.md) +A *header with custom content* has the following specifics: + +- **events**: to handle clicks and other DOM events of the markup returned by the callback, use the [`on`](layout/api/cell/layout_cell_on_config.md) property of the cell with the selector of the necessary element +- **icon and image**: the [`headerIcon`](layout/api/cell/layout_cell_headericon_config.md) and [`headerImage`](layout/api/cell/layout_cell_headerimage_config.md) options work as well. The cell renders the icon and the image before the content that the callback returns +- **height**: the height of a header adjusts to the size of the custom content. The [`headerHeight`](layout/api/cell/layout_cell_headerheight_config.md) option sets a fixed height for it +- **collapsing**: a [`collapsable`](layout/api/cell/layout_cell_collapsable_config.md) cell shows the collapse/expand icon in a header of any type. A click on the custom content of a header calls no API of the cell, so 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 + +@changelog: the ability to set the property as a callback function was added in v9.4 + +**Related samples**: +- [Layout. Header](https://snippet.dhtmlx.com/bxqnzesl) +- [Layout. HTML content in a cell header](https://snippet.dhtmlx.com/lromzzkx) +- [Layout. Toolbar in a cell header](https://snippet.dhtmlx.com/iyci7xt2?mode=wide) +- [Layout. Custom cell headers in a dashboard](https://snippet.dhtmlx.com/awwc1m4u?mode=wide) + +**Related API**: +- [`attach()`](layout/api/cell/layout_cell_attach_method.md) +- [`on`](layout/api/cell/layout_cell_on_config.md) +- [`headerHeight`](layout/api/cell/layout_cell_headerheight_config.md) +- [`headerIcon`](layout/api/cell/layout_cell_headericon_config.md) +- [`headerImage`](layout/api/cell/layout_cell_headerimage_config.md) -[comment]: # (@related: layout/initialization.md#initialize-layout layout/cell_configuration.md#height-of-a-header-cell) +**Related articles**: +- [Layout initialization](layout/initialization.md#initialize-layout) +- [Custom content in a cell header](layout/cell_configuration.md#custom-content-in-a-cell-header) +- [Height of a header cell](layout/cell_configuration.md#height-of-a-header-cell) diff --git a/docs/layout/api/cell/layout_cell_headericon_config.md b/docs/layout/api/cell/layout_cell_headericon_config.md index 4e0953e8..47799ed9 100644 --- a/docs/layout/api/cell/layout_cell_headericon_config.md +++ b/docs/layout/api/cell/layout_cell_headericon_config.md @@ -21,6 +21,11 @@ const layout = new dhx.Layout("layout_container", { **Related sample**: [Layout. Header](https://snippet.dhtmlx.com/bxqnzesl) -[comment]: # (@related: layout/initialization.md#initialize-layout layout/cell_configuration.md#cellheader) - -[comment]: # (@relatedapi: layout/api/layout_header_config.md layout/api/layout_headerheight_config.md layout/api/layout_headerimage_config.md) +**Related API**: +- [`header`](layout/api/cell/layout_cell_header_config.md) +- [`headerImage`](layout/api/cell/layout_cell_headerimage_config.md) +- [`headerHeight`](layout/api/cell/layout_cell_headerheight_config.md) + +**Related articles**: +- [Layout initialization](layout/initialization.md#initialize-layout) +- [Cell header](layout/cell_configuration.md#cell-header) diff --git a/docs/layout/api/cell/layout_cell_headerimage_config.md b/docs/layout/api/cell/layout_cell_headerimage_config.md index 2a57255b..49e97186 100644 --- a/docs/layout/api/cell/layout_cell_headerimage_config.md +++ b/docs/layout/api/cell/layout_cell_headerimage_config.md @@ -19,6 +19,11 @@ const layout = new dhx.Layout("layout_container", { @descr: -[comment]: # (@related: layout/initialization.md#initialize-layout layout/cell_configuration.md#cellheader) +**Related API**: +- [`header`](layout/api/cell/layout_cell_header_config.md) +- [`headerIcon`](layout/api/cell/layout_cell_headericon_config.md) +- [`headerHeight`](layout/api/cell/layout_cell_headerheight_config.md) -[comment]: # (@relatedapi: layout/api/layout_header_config.md layout/api/layout_headerheight_config.md layout/api/layout_headericon_config.md) +**Related articles**: +- [Layout initialization](layout/initialization.md#initialize-layout) +- [Cell header](layout/cell_configuration.md#cell-header) diff --git a/docs/layout/cell_configuration.md b/docs/layout/cell_configuration.md index bf890d15..9794becb 100644 --- a/docs/layout/cell_configuration.md +++ b/docs/layout/cell_configuration.md @@ -6,11 +6,13 @@ description: You can explore the configuration of a Cell of Layout in the docume # 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 the ability of a user to collapse, hide or resize the cell. The sections below go through these settings one by one, while the full list of the available properties is in the [Cell API](layout/api/api_overview.md#cell-api) overview. + ## HTML content -A layout cell can have any HTML content inside it. You can set it with the [](layout/api/cell/layout_cell_html_config.md) attribute in the object of a cell. +A layout cell can have any HTML content inside it. You can set it with the [`html`](layout/api/cell/layout_cell_html_config.md) attribute in the object of a cell. -~~~js +~~~jsx const layout = new dhx.Layout("layout_container", { cols: [ { header: "Cell header", html: "Hello world"} @@ -20,23 +22,11 @@ const layout = new dhx.Layout("layout_container", { **Related sample**: [Layout. HTML content](https://snippet.dhtmlx.com/6x76kgyq) -## Hidden cell - -It is possible to add the [](layout/api/cell/layout_cell_hidden_config.md) attribute into the the object of a cell(s) to render a layout with some cells hidden: - -~~~js -const layout = new dhx.Layout("layout_container", { - cols: [ - { header: "Cell header", hidden:true} - ] -}); -~~~ - ## Cell header Each layout cell can have a header with some text that describes the content of this cell. -~~~js +~~~jsx const layout = new dhx.Layout("layout_container", { cols: [ { header: "Perfect cell header"} @@ -44,9 +34,9 @@ const layout = new dhx.Layout("layout_container", { }); ~~~ -You can also add an icon or an image into the header of a cell with the help of corresponding attributes - [](layout/api/cell/layout_cell_headericon_config.md) and [](layout/api/cell/layout_cell_headerimage_config.md). +You can also add an icon or an image into the header of a cell with the help of corresponding attributes - [`headerIcon`](layout/api/cell/layout_cell_headericon_config.md) and [`headerImage`](layout/api/cell/layout_cell_headerimage_config.md). -~~~js +~~~jsx const layout = new dhx.Layout("layout_container", { cols: [ { header: "Cell header", headerIcon:"/icon.png"} @@ -63,11 +53,11 @@ const layout = new dhx.Layout("layout_container", { **Related sample**: [Layout. Header](https://snippet.dhtmlx.com/bxqnzesl) -## Height of a header cell +### Height of a header cell -You can specify the necessary height of the header of a cell using the [](layout/api/cell/layout_cell_headerheight_config.md) configuration option of the cell: +You can specify the necessary height of the header of a cell using the [`headerHeight`](layout/api/cell/layout_cell_headerheight_config.md) configuration option of the cell: -~~~js +~~~jsx const layout = new dhx.Layout("layout_container", { rows: [ { @@ -84,13 +74,105 @@ const layout = new dhx.Layout("layout_container", { **Related sample**: [Layout. Header](https://snippet.dhtmlx.com/bxqnzesl) -If the [](layout/api/cell/layout_cell_header_config.md) property is not set in the config of a cell, the [](layout/api/cell/layout_cell_headerheight_config.md) option will add a header without text for a cell. +If the [`header`](layout/api/cell/layout_cell_header_config.md) property is not set in the config of a cell, the [`headerHeight`](layout/api/cell/layout_cell_headerheight_config.md) option will add a header without text for a cell. + +## Custom content in a cell header + +Besides a text, the header of a cell can contain HTML markup or a DHTMLX widget. For this purpose, set the [`header`](layout/api/cell/layout_cell_header_config.md) property to a callback function. The component calls the function while it renders the cell. The function takes the configuration object of the cell as a parameter and returns the content for the header. + +The type of the value that you set for the `header` property defines the expected behavior: + +- *a string*: the header shows it as plain text, and the component doesn't interpret HTML tags, it displays them as part of the text +- *a callback function*: tells the component that the header supports HTML content + +A cell with a custom header collapses and expands as any other cell, see the [Collapsibility](layout/cell_configuration.md#collapsibility) section. + +### HTML markup in a header + +To render HTML markup in a header, return a string with the necessary tags from the callback: + +~~~jsx +const layout = new dhx.Layout("layout_container", { + cols: [ + { + id: "orders", + header: cell => `Orders 3 new` + } + ] +}); +~~~ + +**Related sample**: [Layout. HTML content in a cell header](https://snippet.dhtmlx.com/lromzzkx) + +### A DHTMLX widget in a header + +To render a DHTMLX component in a header, return an initialized widget, the same object that you pass to the [`attach()`](layout/api/cell/layout_cell_attach_method.md) method of a cell. The name of a component doesn't work here, as the header treats any returned string as HTML: + +~~~jsx +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**: +- [Layout. Toolbar in a cell header](https://snippet.dhtmlx.com/iyci7xt2?mode=wide) +- [Layout. Custom cell headers in a dashboard](https://snippet.dhtmlx.com/awwc1m4u?mode=wide) + +### Icon, image and height of a custom header + +The [`headerIcon`](layout/api/cell/layout_cell_headericon_config.md) and [`headerImage`](layout/api/cell/layout_cell_headerimage_config.md) 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`](layout/api/cell/layout_cell_headerheight_config.md) option. + +### Events of the header content + +To handle clicks and other DOM events of the markup that the callback returns, use the [`on`](layout/api/cell/layout_cell_on_config.md) property of the cell with the selector of the necessary 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: + +~~~jsx +// builds the HTML content of the cell +function metrics() { + return `