Skip to content

Commit 0012371

Browse files
committed
[update] improve grid row expander guide and api
1 parent 667f938 commit 0012371

File tree

4 files changed

+141
-54
lines changed

4 files changed

+141
-54
lines changed

docs/grid/api/grid_getsubrow_method.md

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,48 @@ Note that the method works if a sub-row is in the visible area or if the `preser
1818
- `id: string | number` - the id of a row
1919

2020
@returns:
21-
An object that includes:
22-
- the configuration of the sub-row, including both user-defined settings and the default settings (`expanded`, `fullWidth`, `padding`, `height`, `toggleItem`, `preserve`, `css`)
23-
- `element: HTMLElement | null` - the parent container of the current sub-row
24-
- `view: string | object | null`:
25-
- a *string*, if the sub-row is set by the HTML content
26-
- an *object* instance to interact with, if a sub-row is an instance of a nested component (for example, Grid)
27-
- *null*, if the sub-row is unavailable (for example, it is hidden or placed outside the visible area and the `preserve` config is not specified)
21+
An object that includes the following properties:
22+
23+
<table>
24+
<tbody>
25+
<tr>
26+
<td><b>css</b></td>
27+
<td>(<i>string</i>) user-defined CSS classes for a sub-row</td>
28+
</tr>
29+
<tr>
30+
<td><b>element</b></td>
31+
<td>(<i>HTMLElement | null</i>) the parent container of the current sub-row</td>
32+
</tr>
33+
<tr>
34+
<td><b>expanded</b></td>
35+
<td>(<i>boolean</i>) defines whether a sub-row is expanded by default, <i>false</i> by default</td>
36+
</tr>
37+
<tr>
38+
<td><b>fullWidth</b></td>
39+
<td>(<i>boolean</i>) defines whether a sub-row will take all the width of Grid, <i>false</i> by default</td>
40+
</tr>
41+
<tr>
42+
<td><b>height</b></td>
43+
<td>(<i>number</i>) the height of a sub-row in pixels, <i>200</i> by default</td>
44+
</tr>
45+
<tr>
46+
<td><b>padding</b></td>
47+
<td>(<i>string | number</i>) the inner padding of a sub-row, <i>8</i> by default</td>
48+
</tr>
49+
<tr>
50+
<td><b>preserve</b></td>
51+
<td>(<i>boolean</i>) saves the state of sub-rows while expanding/collapsing, disappearing from the visible area, data updating, <i>false</i> by default</td>
52+
</tr>
53+
<tr>
54+
<td><b>toggleIcon</b></td>
55+
<td>(<i>boolean</i>) enables the icon for expanding/collapsing, <i>true</i> by default</td>
56+
</tr>
57+
<tr>
58+
<td><b>view</b></td>
59+
<td>(<i>string | object | null</i>) that can be presented by:<ul><li>a <i>string</i>, if the sub-row is set by the HTML content</li><li>an <i>object</i> instance to interact with, if a sub-row is an instance of a nested component (for example, Grid)</li><li><i>null</i>, if the sub-row is unavailable (for example, it is hidden or placed outside the visible area and the `preserve` config is not specified)</li></ul></td>
60+
</tr>
61+
</tbody>
62+
</table>
2863

2964
**Related article:** [Getting sub-row config and content](grid/configuration.md#getting-sub-row-config-and-content)
3065

docs/grid/api/grid_subrow_config.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Note that when the `subRow` config is used, Grid doesn't support the [TreeGrid m
1818

1919
## Parameters
2020

21-
The `subRow` property is a callback function which is called with the row object as a parameter and returns an HTML string or a constructor of a subGrid (or any other nested Suite component).
21+
The `subRow` property is a callback function which is called with the row object as a parameter and returns HTML as string or a constructor of a subGrid (or any other nested Suite component).
2222

2323
### Example
2424

@@ -38,7 +38,7 @@ const grid = new dhx.Grid("grid_container", {
3838
});
3939
~~~
4040

41-
- a sub-row with a subGrid
41+
- a sub-row with a subgrid
4242

4343
~~~jsx {7-16}
4444
const grid = new dhx.Grid("grid_container", {

docs/grid/api/grid_subrowconfig_config.md

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ The `subRowConfig` object may contain the following properties:
2323
- `expanded` - (*boolean*) defines whether a sub-row is expanded by default, *false* by default
2424
- `preserve` - (*boolean*) saves the state of sub-rows while expanding/collapsing, disappearing from the visible area, data updating, *false* by default
2525
- `toggleIcon` - (*boolean*) enables the icon for expanding/collapsing, *true* by default
26-
- `height` - (*number*) the height of a sub-row in pixels, *200* by default
27-
- `padding` - (*string|number*) the inner padding of a sub-row, *8* by default
26+
- `height` - (*number*) the height of a sub-row in pixels, [controls the visibility of sub-rows](grid/configuration.md#adding-sub-rows-for-specific-rows), *200* by default
27+
- `padding` - (*string* | *number*) the inner padding of a sub-row, *8* by default
2828
- `css` - (*string*) user-defined CSS classes for a sub-row
2929
- `fullWidth` - (*boolean*) defines whether a sub-row will take all the width of Grid, *false* by default
3030

@@ -54,23 +54,31 @@ const grid = new dhx.Grid("grid_container", {
5454

5555
- configuring sub-rows settings dynamically
5656

57-
~~~jsx {7-11}
57+
The `height` setting of the `subRowConfig` property (set as a callback function) allows you to control the visibility of sub-rows. Set the `height` setting to 0 if you don't want a sub-row to be created for particular rows.
58+
59+
~~~jsx {7-10}
5860
const grid = new dhx.Grid("grid_container", {
59-
columns: [
60-
{ id: "zone_name", header: [{ text: "Zone name" }] },
61-
{ id: "temperature", header: [{ text: "Temperature" }] },
61+
columns:[
62+
// columns config
6263
],
6364
data: dataset,
65+
autoWidth: true,
6466
subRowConfig: (row) => ({
65-
height: 200,
66-
expanded: row.temperature > 30,
67-
css: row.temperature > 30 ? "hot-zone" : "cool-zone",
67+
height: row.data.length ? 250 : 0,
68+
expanded: true
69+
}),
70+
subRow: (row) => new dhx.Grid(null, {
71+
columns: [
72+
// columns config
73+
],
74+
data: row.data
6875
}),
69-
subRow: ({ zone_name }) => `<div>Details for ${zone_name}</div>`,
7076
});
7177
~~~
7278

73-
**Related sample:** [Grid. Row expander. Full config](https://snippet.dhtmlx.com/xdw2037t)
79+
**Related sample:**
80+
- [Grid. Row expander. Full config](https://snippet.dhtmlx.com/xdw2037t)
81+
- [Grid. Row expander. Subgrid only in specific rows](https://snippet.dhtmlx.com/03udbtmr)
7482

7583
**Related article:** [Row expander](grid/configuration.md#row-expander)
7684

docs/grid/configuration.md

Lines changed: 78 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,15 +1620,15 @@ const grid = new dhx.Grid("grid_container", {
16201620

16211621
## Row expander
16221622

1623-
The row expander functionality allows using nested content in Grid sub-rows. You can add a Grid or any other Suite widget, as well as some HTML content into a sub-row. The number of Grid nesting levels is unlimited.
1623+
The row expander functionality allows using nested content in Grid sub-rows. You can add a Grid or any other Suite widget, as well as some HTML content into a sub-row.
16241624

16251625
:::tip Pro version only
16261626
This functionality requires PRO version of the DHTMLX Grid (or DHTMLX Suite) package.
16271627
:::
16281628

16291629
### Adding sub-rows
16301630

1631-
In order to enable the row expander feature, you should use the [`subRow`](grid/api/grid_subrow_config.md) configuration option. It defines the content of sub-rows for each row of the Grid. The `subRow` property is a callback function which is called with the row object as a parameter and returns an HTML string or the constructor of a subGrid (or any other nested Suite component).
1631+
In order to enable the row expander feature, you should use the [`subRow`](grid/api/grid_subrow_config.md) configuration option. It defines the content of sub-rows for each row of the Grid. The `subRow` property is a callback function which is called with the row object as a parameter and should return an HTML string or the constructor of a Suite component (Grid, Chart, Form, DataView, etc.).
16321632

16331633
:::note
16341634
Note that when the `subRow` config is used, Grid doesn't support the [TreeGrid mode](grid/treegrid_mode.md) and the [data grouping](grid/usage.md#grouping-data) functionality.
@@ -1650,7 +1650,7 @@ const grid = new dhx.Grid("grid_container", {
16501650
});
16511651
~~~
16521652

1653-
In the example below a sub-row contains a subGrid:
1653+
In the example below a sub-row contains a subgrid:
16541654

16551655
~~~jsx {7-16}
16561656
const grid = new dhx.Grid("grid_container", {
@@ -1739,40 +1739,47 @@ const grid = new dhx.Grid("grid_container", {
17391739

17401740
In the above example the sub-rows are dynamically configured depending on the value in the column with the "temperature" id. If the temperature value is more than 30, a sub-row will be expanded and gets the CSS "hot-zone" class (or "cool-zone", if the temperature value is less than 30). The height of an expanded sub-row cell will be 200px.
17411741

1742-
In the following example the [`subRowConfig`](grid/api/grid_subrowconfig_config.md) config set as a callback function defines that the rows that have the "Critical" status in the column with the "health_status" id will be expanded on initialization of the Grid. The height of an expanded sub-row cell will be 250px.
1742+
#### Adding sub-rows for specific rows
17431743

1744-
~~~jsx {5-8}
1744+
You can define which row a sub-row should be created for with the help of the `height` property of the [`subRowConfig`](grid/api/grid_subrowconfig_config.md) configuration option. If you don't want to create sub-rows for particular rows, specify the `height:0` setting in the `subRowConfig` property.
1745+
1746+
:::note
1747+
The described functionality works only if the `subRowConfig` property is initialized as a callback function.
1748+
:::
1749+
1750+
~~~jsx {7-10}
17451751
const grid = new dhx.Grid("grid_container", {
1746-
columns,
1747-
data,
1748-
rowCss: row => (row.health_status === "Critical" && "overheating") || "",
1749-
subRowConfig: row => ({
1750-
height: 250,
1751-
expanded: row.health_status === "Critical",
1752+
columns: [
1753+
// columns config
1754+
],
1755+
data: dataset,
1756+
autoWidth: true,
1757+
subRowConfig: (row) => ({
1758+
height: row.data.length ? 250 : 0,
1759+
expanded: true
17521760
}),
1753-
subRow: ({ data }) => new dhx.Grid(null, {
1761+
subRow: (row) => new dhx.Grid(null, {
17541762
columns: [
1755-
{ id: "component", header: [{ text: "Component" }] },
1756-
{ id: "temperature", header: [{ text: "Temperature" }], numberMask: { suffix: "°C" } },
1757-
{ id: "critical_threshold", header: [{ text: "Critical Threshold" }], numberMask: { suffix: "°C" } },
1758-
{ id: "status", header: [{ text: "Status" }] },
1763+
// columns config
17591764
],
1760-
data,
1761-
autoWidth: true
1765+
data: row.data
17621766
}),
1763-
autoWidth: true
17641767
});
17651768
~~~
17661769

1767-
**Related sample:** [Grid. Row expander. Subgrid with rows expanded by criteria](https://snippet.dhtmlx.com/pbubj175)
1770+
In the above example the [`subRowConfig`](grid/api/grid_subrowconfig_config.md) config set as a callback function defines that sub-rows with the height 250px will be created for rows that have some data. For rows without data the `height:0` setting is specified, so sub-rows won't be created for these rows.
1771+
1772+
**Related sample:** [Grid. Row expander. Subgrid only in specific rows](https://snippet.dhtmlx.com/03udbtmr)
17681773

17691774
### Saving state of nested components or data in sub-rows
17701775

17711776
You can save the state of the nested components or the data of sub-rows while updating data, scrolling or collapsing sub-rows by using the `preserve` property of the [`subRowConfig`](grid/api/grid_subrowconfig_config.md) configuration option of Grid. By default, sub-rows are destroyed when they are hidden (e.g. if a row leaves the visible area during scrolling) or collapsed, which leads to resetting of any changes made in the inner components.
17721777

1773-
When the `preserve: true` setting is specified, sub-rows save their content even after being destroyed or hidden. It means that any change (such as sorting, data input or state change) is saved and the sub-row is restored in the same state when displayed again.
1778+
When the `preserve: true` setting is specified, sub-rows aren't destroyed when hidden or collapsed and their content is saved. It means that any change (such as sorting, data input or state change) is saved and the sub-row is restored in the same state when displayed again.
17741779
1775-
However, it's important to take into account that this option increases the size of the used memory, since the sub-rows data are kept in the memory even when they aren't displayed.
1780+
:::info note
1781+
It's important to take into account that the `preserve: true` setting increases the size of the used memory, since the sub-rows data are kept in the memory even when they aren't displayed.
1782+
:::
17761783
17771784
#### When using `preserve` is useful
17781785
@@ -1835,7 +1842,7 @@ const grid = new dhx.Grid("grid_container", {
18351842
});
18361843
~~~
18371844
1838-
In the above example the `load()` method of [DataCollection](/data_collection/) is used for loading data into subGrid.
1845+
In the above example the `load()` method of [DataCollection](/data_collection/) is used for loading data into a nested Grid.
18391846
18401847
**Related sample:** [Grid. Row expander. Subgrid data loading](https://snippet.dhtmlx.com/03ndqrqt)
18411848
@@ -1906,11 +1913,10 @@ It is possible to create as many levels of nested subGrids, as necessary. To spe
19061913

19071914
- create a Grid with columns and data
19081915
- in the Grid configuration specify the [`subRow`](grid/api/grid_subrow_config.md) option as a callback function, which:
1909-
- is called with an array of data that should be placed in the sub-row as a parameter
1910-
- returns a subGrid that contains the `subRow` config set as a callback function that may return:
1916+
- returns a nested Grid that contains the `subRow` config set as a callback function that may return:
19111917
- some Suite component
1912-
- an HTML string
1913-
- a subGrid instance for another nesting level (that contains the `subRow` config set as a callback function to return another subGrid, Suite component, or HTML content)
1918+
- HTML as string
1919+
- a subgrid instance for another nesting level (that contains the `subRow` config set as a callback function to return another subgrid, a Suite component, or HTML content)
19141920

19151921
Check the example below:
19161922

@@ -1964,6 +1970,10 @@ const grid = new dhx.Grid("grid_container", {
19641970

19651971
You can adjust the sub-row width depending on the width of its parent Grid via the `fullWidth` property of the [`subRowConfig`](grid/api/grid_subrowconfig_config.md) configuration object.
19661972

1973+
:::info note
1974+
The `fullWidth` property works only if the `subRowConfig` property is initialized as an object.
1975+
:::
1976+
19671977
If the `fullWidth: true` configuration option is specified, the sub-row width is the same as the full width of the Grid content, including the area outside the visible area borders (it means that the sub-row will be scrolled together with the horizontal scroll). By default, a sub-row takes just the width of the visible Grid area.
19681978

19691979
Check the example below:
@@ -2000,14 +2010,48 @@ You can get the configuration settings applied to a sub-row and the content insi
20002010
Note that the method works if a sub-row is in the visible area or if the `preserve:true` property is specified in the `subRowConfig` object of the sub-row.
20012011
:::
20022012
2003-
The method returns an object that includes:
2013+
The method takes as a parameter the id of a row and returns an object that includes the following properties:
20042014
2005-
- the configuration of the sub-row, including both user-defined settings and the default settings (`expanded`, `fullWidth`, `padding`, `height`, `toggleItem`, `preserve`, `css`)
2006-
- `element: HTMLElement | null` - the parent container of the current sub-row
2007-
- `view: string | object | null`:
2008-
- a *string*, if the sub-row is set by the HTML content
2009-
- an object instance you can interact with, if a sub-row is an instance of a nested component (for example, Grid)
2010-
- *null*, if the sub-row is unavailable (for example, it is hidden or placed outside the visible area and the `preserve` config is not specified)
2015+
<table>
2016+
<tbody>
2017+
<tr>
2018+
<td><b>css</b></td>
2019+
<td>(<i>string</i>) user-defined CSS classes for a sub-row</td>
2020+
</tr>
2021+
<tr>
2022+
<td><b>element</b></td>
2023+
<td>(<i>HTMLElement | null</i>) the parent container of the current sub-row</td>
2024+
</tr>
2025+
<tr>
2026+
<td><b>expanded</b></td>
2027+
<td>(<i>boolean</i>) defines whether a sub-row is expanded by default, <i>false</i> by default</td>
2028+
</tr>
2029+
<tr>
2030+
<td><b>fullWidth</b></td>
2031+
<td>(<i>boolean</i>) defines whether a sub-row will take all the width of Grid, <i>false</i> by default</td>
2032+
</tr>
2033+
<tr>
2034+
<td><b>height</b></td>
2035+
<td>(<i>number</i>) the height of a sub-row in pixels, <i>200</i> by default</td>
2036+
</tr>
2037+
<tr>
2038+
<td><b>padding</b></td>
2039+
<td>(<i>string | number</i>) the inner padding of a sub-row, <i>8</i> by default</td>
2040+
</tr>
2041+
<tr>
2042+
<td><b>preserve</b></td>
2043+
<td>(<i>boolean</i>) saves the state of sub-rows while expanding/collapsing, disappearing from the visible area, data updating, <i>false</i> by default</td>
2044+
</tr>
2045+
<tr>
2046+
<td><b>toggleIcon</b></td>
2047+
<td>(<i>boolean</i>) enables the icon for expanding/collapsing, <i>true</i> by default</td>
2048+
</tr>
2049+
<tr>
2050+
<td><b>view</b></td>
2051+
<td>(<i>string | object | null</i>) that can be presented by:<ul><li>a <i>string</i>, if the sub-row is set by the HTML content</li><li>an <i>object</i> instance to interact with, if a sub-row is an instance of a nested component (for example, Grid)</li><li><i>null</i>, if the sub-row is unavailable (for example, it is hidden or placed outside the visible area and the `preserve` config is not specified)</li></ul></td>
2052+
</tr>
2053+
</tbody>
2054+
</table>
20112055
20122056
## Drag-n-drop
20132057

0 commit comments

Comments
 (0)