Skip to content

Commit c7a97bd

Browse files
committed
[update] headerShape.cellStyle added, style cells updated, render-table, template fixed
1 parent 15dbca2 commit c7a97bd

File tree

6 files changed

+89
-38
lines changed

6 files changed

+89
-38
lines changed

docs/api/config/headershape-property.md

+13-4
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,15 @@ headerShape?: {
2222

2323
### Parameters
2424

25-
- `collapsible` - (optional) if set to **true**, dimension groups in the table are collapsible; it's set to **false** by default
26-
- `vertical` - (optional) if set to **true**, changes the text orientation in all headers from horizontal to vertical; the default value is **false**
27-
- `template` - (optional) defines the format of text in headers; by default, for the fields applied as rows the value of the `label` parameter is displayed and for the fields applied as values the label and method are shown (e.g., *Oil(count)*); the function takes the field id, label and the method or predicate id (if any) and returns the processed value; the default template is as follows:
25+
- `collapsible` - (optional) if set to **true**, dimension groups in the table are collapsible. It's set to **false** by default
26+
- `vertical` - (optional) if set to **true**, changes the text orientation in all headers from horizontal to vertical. The default value is **false**
27+
- `cellStyle` - (optional) a function that applies a custom style to a header or footer cell. The function returns a name of css class and takes the following parameters:
28+
- `field` (string) - (required) a string representing the field name the cell corresponds to. For the header of the tree column the field is ""
29+
- `value` (string | number | date) - (required) the value of a cell
30+
- `area` - (required) a string indicating the area of the table where a cell resides ("rows", "columns" or "values" area)
31+
- `method` string - (optional) a string that can represent the operation performed for a field from the "values` area (e.g., "sum", "count", etc.) or the name of a predicate set for a field from the "columns" area
32+
- `isTotal` - (optional) defines whether a cell belongs to a total column
33+
- `template` - (optional) defines the format of text in headers. By default, for the fields applied as rows the value of the `label` parameter is displayed and for the fields applied as values the label and method are shown (e.g., *Oil(count)*). The function takes the field id, label and the method or predicate id (if any) and returns the processed value. The default template is as follows:
2834
~~~js
2935
template: (label, id, subLabel) =>
3036
label + (subLabel ? ` (${subLabel})` : "")
@@ -61,5 +67,8 @@ const table = new pivot.Pivot("#root", {
6167
- [Pivot 2. Vertical orientation of text in grid headers](https://snippet.dhtmlx.com/4qroi8ka)
6268
- [Pivot 2. Collapsible columns](https://snippet.dhtmlx.com/pt2ljmcm)
6369
- [Pivot 2. Headers template](https://snippet.dhtmlx.com/g89r9ryw)
70+
- [Pivot 2. Pivot 2: Adding сustom CSS for table and header cells](https://snippet.dhtmlx.com/nfdcs4i2)
6471

65-
**Related article**: [Configuration](/guides/configuration)
72+
**Related articles**:
73+
- [Configuration](/guides/configuration)
74+
- [Cell style](/guides/stylization/#cell-style)

docs/api/config/tableshape-property.md

+11-8
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,25 @@ tableShape?: {
4848
- `templates` - (optional) allows setting templates to a cell; it's an object where:
4949
- each key is a field id
5050
- the value is a function that returns a string and receives cell value and operation. All columns based on the specified field will have the related template applied. For example, it allows setting the units of measurement or returning the required number of digits after the decimal point for numeric values, etc. See the example below.
51-
- `marks` - (optional) allows marking a cell with the required values; it's an object where keys are CSS class names and values are either a function or one of the predefined strings ("max", "min"). The function should return boolean for the checked value; if **true** is returned, the css class is assigned to the cell. More information with examples see here [Marking cells](/guides/stylization#cell-style).
51+
- `marks` - (optional) allows marking a cell with the required values. It's an object where keys are CSS class names and values are either a function or one of the predefined strings ("max", "min"). The function should return boolean for the checked value. If **true** is returned, the css class is assigned to the cell. More information with examples see here [Marking cells](/guides/stylization#cell-style).
5252
- `sizes` - (optional) defines the following size parameters of the table:
53-
- `rowHeight` - (optional) the row height in the Pivot table in pixels; the default value is 34
53+
- `rowHeight` - (optional) the row height in the Pivot table in pixels. The default value is 34
5454
- `headerHeight` - (optional) the header height in pixels; the default value is 30
5555
- `footerHeight` - (optional) the footer height in pixels; the default value is 30
5656
- `columnWidth` - (optional) the column width in pixels; the default value is 150
57-
- `cellStyle` - (optional) a function that applies a custom style to a cell; the function has the next parameters:
57+
- `cellStyle` - (optional) a function that applies a custom style to a cell. The function has the next parameters:
5858
- `field` - (required) a string representing the field name for which the style is applied
5959
- `value` - (required) the value of the cell (the actual data for that particular row and column)
6060
- `area` - (required) a string indicating the area of the table where a cell resides ("rows", "columns" or "values" area)
6161
- `method` - (optional) a string that can represent the operation performed on a cell (e.g., "sum", "count", etc.)
6262
- `isTotal` - (optional) defines whether a cell belongs to a total row, total column, or both: "row"|"column"|"both
6363
The `cellStyle` function returns a string, which can be used as a CSS class name to apply specific styles to a cell.
64-
- `tree` - (optional) if set to **true**, enables the tree mode when data can be presented with expandable rows; the default value is **false**; more information with examples see here [Switching to the tree mode](/guides/configuration/#enabling-the-tree-mode)
65-
- `totalColumn` - (optional) if **true**, enables generating the total column with total values for rows (**false** is set by default); if the value is set to "sumOnly", the column with the total sum value will be generated (available only for sum operations)
66-
- `totalRow` - (optional) if **true**, enables generating the footer with total values (**false** is set by default); if the value is set to "sumOnly", the row with the total row value will be generated (available only for sum operations)
64+
- `tree` - (optional) if set to **true**, enables the tree mode when data can be presented with expandable rows, the default value is **false**. More information with examples see here [Switching to the tree mode](/guides/configuration/#enabling-the-tree-mode)
65+
- `totalColumn` - (optional) if **true**, enables generating the total column with total values for rows (**false** is set by default). If the value is set to "sumOnly", the column with the total sum value will be generated (available only for sum operations)
66+
- `totalRow` - (optional) if **true**, enables generating the footer with total values (**false** is set by default). If the value is set to "sumOnly", the row with the total row value will be generated (available only for sum operations)
6767
- `cleanRows` - (optional) if set to **true**, the duplicate values in scale columns are hidden in the table view. The default value is **false**
6868
- `split` - (optional) allows freezing columns on the right or left depending on the parameter specified (refer to [Freezing columns](/guides/configuration/#freezing-columns)):
69-
- `left` (boolean) - if set to **true** (**false** is set by default), fixes the columns from the left, which makes columns static and visible while scrolling; the number of columns that are split is equal to the number of the rows fields that are defined in the [`config`](/api/config/config-property) property.
69+
- `left` (boolean) - if set to **true** (**false** is set by default), fixes the columns from the left, which makes columns static and visible while scrolling. The number of columns that are split is equal to the number of the rows fields that are defined in the [`config`](/api/config/config-property) property
7070
- `right` (boolean) - fixes total columns on the right; default value is **false**
7171

7272
By default, `tableShape` is undefined, implying that no total row, no total column is present, no templates and marks are applied, the data is shown as a table and not a tree, and columns are not fixed during scroll.
@@ -113,5 +113,8 @@ const table = new pivot.Pivot("#root", {
113113
- [Pivot 2. Frozen (fixed) columns](https://snippet.dhtmlx.com/lahf729o)
114114
- [Pivot 2. Set row, header, footer height and all columns width](https://snippet.dhtmlx.com/x46uyfy9)
115115
- [Pivot 2. Clean rows](https://snippet.dhtmlx.com/rwwhgv2w?tag=pivot)
116+
- [Pivot 2. Pivot 2: Adding сustom CSS for table and header cells](https://snippet.dhtmlx.com/nfdcs4i2)
116117

117-
**Related article**: [Configuration](/guides/configuration)
118+
**Related articles**:
119+
- [Configuration](/guides/configuration)
120+
- [Cell style](/guides/stylization/#cell-style)

docs/api/events/render-table-event.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ The callback of the action takes the `config` object with the following paramete
4242

4343
- `columns` - (optional) columns array with the next parameters for each object:
4444
- `id` (number) - (required) the id of a column
45-
- `cell` (any) - (optional) a template with the cell content (please, refer to [Applying templates to cells](/guides/configuration/#applying-templates-to-cells))
45+
- `cell` (any) - (optional) a template with the cell content (please, refer to [Adding templates via the template helper](/guides/configuration/#adding-a-template-via-the-template-helper))
46+
- `template` - (optional) the template that is defined via the [`tableShape`](/api/config/tableshape-property) property
4647
- `fields` (array) - (optional) defines fields in the hierarchical column in the tree mode. Reflects fields displayed in this column on different levels
48+
- `field` - (optional) it's a string which is the id of a field
4749
- `method` (string) - (optional) a method, if defined for a field in this column
4850
- `methods` (array) - (optional) defines methods applied to fields in the hierarchical column in the tree mode
4951
- `format` (string or object) - (required) [date format](/guides/custom-formatting/#custom-date-formatting) or [number format](/guides/custom-formatting/#custom-number-formatting)
@@ -59,9 +61,7 @@ The callback of the action takes the `config` object with the following paramete
5961
- `method` (string) - (required) the field predicate, if a cell belongs to "columns" area and predicate is defined
6062
- `format` (string or object) - [date format](/guides/custom-formatting/#custom-date-formatting) or [number format](/guides/custom-formatting/#custom-number-formatting)
6163
- `footer` - (optional) a header label or an object with footer settings which are the same as the header settings
62-
- `field` - (optional) it's a string which is the id of a field
63-
- `template` - (optional) the template that is defined via the [`tableShape`](/api/config/tableshape-property) property
64-
- `data` - (optional) an array of objects with data for the table; each object represents a row:
64+
- `data` - (optional) an array of objects with data for the table; each object represents a row:
6565
- `id` (number) - (required) row id
6666
- `values` (array) - (required) an array with row data
6767
- `open` (boolean)- (optional) branch state

docs/api/helpers/template.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ For body cells the function takes the next parameters:
3535
- `$level` (boolean)- (optional) branch index
3636
- `column` - (required) an object with column data:
3737
- `id` (number) - (required) the id of a column
38-
- `cell` (any) - (optional) a template with the cell content (please, refer to [Applying templates to cells](/guides/configuration/#applying-templates-to-cells))
38+
- `cell` (any) - (optional) a template with the cell content (please, refer to [Adding templates via the template helper](/guides/configuration/#adding-a-template-via-the-template-helper))
39+
- `template` - (optional) the template that is defined via the [`tableShape`](/api/config/tableshape-property) property
3940
- `fields` (array) - (optional) defines fields in the hierarchical column in the tree mode. Reflects fields displayed in this column on different levels
41+
- `field` - (optional) it's a string which is the id of a field
4042
- `method` (string) - (optional) a method, if defined for a field in this column
4143
- `methods` (array) - (optional) defines methods applied to fields in the hierarchical column in the tree mode
4244
- `format` (string or object) - (required) [date format](/guides/custom-formatting/#custom-date-formatting) or [number format](/guides/custom-formatting/#custom-number-formatting)
@@ -49,12 +51,12 @@ For body cells the function takes the next parameters:
4951
- `colspan` (number) - (optional) the number of columns a header should span
5052
- `value` (any) - (required) raw value, if a cell belongs to "columns" area
5153
- `field` (string) - (required) a field, which value is displayed, if a cell belongs to "columns" area
52-
- `method` (string) - (required) a field predicate, if a cell belongs to "columns" area and predicate is defined
53-
- `format` (string or object) - (required) [date format](/guides/custom-formatting/#custom-date-formatting) or [number format](/guides/custom-formatting/#custom-number-formatting)
54+
- `method` (string) - (required) the field predicate, if a cell belongs to "columns" area and predicate is defined
55+
- `format` (string or object) - [date format](/guides/custom-formatting/#custom-date-formatting) or [number format](/guides/custom-formatting/#custom-number-formatting)
5456

5557
For header cells the function parameters are the following:
5658

57-
- `value` (any) - (required) raw cell value
59+
- `value` (any) - (required) a raw cell value
5860
- `method` (string) - (optional) a predicate used for a column
5961
- `field` (string) - (optional) a field which value is displayed in a cell
6062
- `cell` - (required) an object with cell data:

docs/guides/configuration.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ const table = new pivot.Pivot("#root", {
170170

171171
### Adding a template via the template helper
172172

173-
You can also define HTML templates using the [`pivot.template`](/api/helpers/template) helper. You need to apply it right before the table renders, which is done by intercepting the [render-table](/api/events/render-table-event) event using the [api.intercept()](/api/internal/intercept-method) method. Use this event to modify the table's config, namely the `columns` array. Define the template via the `pivot.template` helper.
173+
You can also define a template as a cell property of the `column` object via the [`pivot.template`](/api/helpers/template) helper. You need to apply it right before the table renders, which is done by intercepting the [render-table](/api/events/render-table-event) event using the [api.intercept()](/api/internal/intercept-method) method. Use this event to modify the table's config, namely the `columns` array. Define the template via the `pivot.template` helper.
174174

175175
The example shows how you can add icons (star or flag icon) to body cells based on their field (id, user_score):
176176

@@ -201,7 +201,7 @@ function scoreTemplate(value) {
201201
widget.api.intercept("render-table", ({ config: tableConfig }) => {
202202
tableConfig.columns = tableConfig.columns.map((c) => {
203203
if (c.area === "rows") {
204-
// Apply a template to body cells in row fields
204+
// Apply a template to column cells from the "rows" area
205205
c.cell = pivot.template(({ value, method, row, column }) => cellTemplate(value, method, row, column));
206206
}
207207
return c;
@@ -251,7 +251,7 @@ const table = new pivot.Pivot("#root", {
251251
252252
### Adding templates via the template helper
253253
254-
You can also define HTML templates using the [`pivot.template`](/api/helpers/template) helper. You need to apply it right before the table renders, which is done by intercepting the [render-table](/api/events/render-table-event) event using the [api.intercept()](/api/internal/intercept-method) method. Use this event to modify the table's config, namely the `header` parameter in the `columns` array. Define the template via the `pivot.template` helper.
254+
You can also define a template as a cell property of the `header` object via the [`pivot.template`](/api/helpers/template) helper. You need to apply it right before the table renders, which is done by intercepting the [render-table](/api/events/render-table-event) event using the [api.intercept()](/api/internal/intercept-method) method. Use this event to modify the table's config, namely the `header` parameter in the `columns` array. Define the template via the `pivot.template` helper.
255255
256256
The example below shows how to add icons to:
257257
@@ -276,10 +276,10 @@ function statusTemplate(value) {
276276
widget.api.intercept("render-table", ({ config: tableConfig }) => {
277277
tableConfig.columns = tableConfig.columns.map((c) => {
278278
if (c.area === "rows") {
279-
// Apply a template to the first header row of row fields
279+
// Apply a template to the first header row of the columns from the "rows" area
280280
c.header[0].cell = pivot.template(({ value, field }) => rowsHeaderTemplate(value, field));
281281
} else {
282-
// For headers in columns (like "status")
282+
// For header cells that display values from the "status" field
283283
const headerCell = c.header.find((h) => h.field === "status");
284284
if (headerCell) {
285285
headerCell.cell = pivot.template(({ value }) => statusTemplate(value));

0 commit comments

Comments
 (0)