Skip to content

Commit f405ed1

Browse files
authored
Merge pull request #29 from DHTMLX/next
[update] update for vers Pviot 2.1
2 parents 955b7d6 + 7918fa1 commit f405ed1

31 files changed

+1555
-687
lines changed

docs/api/config/columnshape-property.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ columnShape?: {
3636
- `autoWidth` - (optional) an object that defines how column width should be calculated automatically. The default configuration uses 20 rows, and the width is calculated based on the header and data, with each field analyzed only once. The object parameters are the following:
3737
- `columns` - (optional) an object where each key is a field id and the boolean value defines whether column width should be calculated automatically
3838
- `auto` - (required) if set to **header**, adjusts the width to the header text; if set to **data**, adjusts the width to the cell with the widest content; if set to **true**, the width is adjusted to the content of both headers and cell.
39-
If autowidth is set to **false**, the `width` value is set or the value of the `colWidth` from the [`tableShape`](/api/config/tableshape-property) property is applied.
39+
If autowidth is set to **false**, the `width` value is set or the value of the `columnWidth` from the [`tableShape`](/api/config/tableshape-property) property is applied.
4040
- `maxRows` - (optional) the number of rows to be processed for the autoWidth calculation
4141
- `firstOnly` - (optional) if set to **true** (default), each field of the same data is analyzed only once to calculate the column width; in case of multiple columns based on the same data (e.g., the *oil* field with the *count* operation and the *oil* field with the *sum* operation), only data in the first one will be analyzed and the others will inherit this width
4242

@@ -78,5 +78,5 @@ const table = new pivot.Pivot("#root", {
7878
~~~
7979

8080
**Related samples:**
81-
- [Pivot 2.0. Auto width. Sizing columns to content](https://snippet.dhtmlx.com/tn1yw14m)
82-
- [Pivot 2.0. Set columns width](https://snippet.dhtmlx.com/ceu34kkn)
81+
- [Pivot 2. Auto width. Sizing columns to content](https://snippet.dhtmlx.com/tn1yw14m)
82+
- [Pivot 2. Set columns width](https://snippet.dhtmlx.com/ceu34kkn)

docs/api/config/fields-property.md

+23-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ fields?: [{
1919
id: string,
2020
label?: string,
2121
type: "number" | "date" | "text",
22-
sort?: "asc" | "desc" | ((a: any, b: any) => number)
22+
sort?: "asc" | "desc" | ((a: any, b: any) => number),
23+
format?: string | boolean | numberFormatOptions{}
2324
}];
2425
~~~
2526

@@ -33,6 +34,20 @@ Each object in the `fields` array should have the following properties:
3334
- `label` - (optional) the field label to be displayed in GUI
3435
- `type` - (required) data type in a field ( "number", "date", or "string")
3536
- `sort` - (optional) defines the default sorting order for the field. Accepts "asc", "desc", or a custom sorting function
37+
- `format` - (optional) allows customizing the format of numbers and dates in a field; the format will be also applied during [export](/guides/exporting-data)
38+
- `string` - (optional) the format for dates (by default, Pivot uses `dateFormat` from locale)
39+
- `boolean` - (optional) if set to **false**, a number is displayed as is, without any formatting
40+
- `numberFormatOptions` - (optional) an object with options for formatting numeric fields; by default, numbers will be shown with a maximum of 3 decimal digits and group separation for the integer part is applied.
41+
- `minimumIntegerDigits`(number) - (optional) the minimum number of integer (for example, if the value is set to 2, the number 1 will be shown as "01"); the default is 1;
42+
- `minimumFractionDigits`(number) - (optional) the minimum number of fraction digits to use (for example, if the value is set to 2, the number 10.5 will be shown as "10.50"); the default is 1;
43+
- `maximumFractionDigits`(number) - (optional) the maximum number of fraction digits to use (for example, if the value is set to 2, the number 10.3333... will be shown as "10.33"); the default is 3;
44+
For more details about digit options refer to [Digit options](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#minimumintegerdigits)
45+
- `prefix` (string) - (optional) a string (before a number) for additional symbols like currency
46+
- `suffix` (string) - (optional) a string (after a number) for additional symbols like currency
47+
48+
:::info
49+
If a template is applied via the [`tableShape`](/api/config/tableshape-property) property, it will override the `format` settings.
50+
:::
3651

3752
### Example
3853

@@ -88,3 +103,10 @@ const table = new pivot.Pivot("#root", {
88103
}
89104
});
90105
~~~
106+
107+
**Related articles**:
108+
109+
- [Number formatting](/guides/localization/#number-formatting)
110+
- [Applying formats to fields](/guides/working-with-data/#applying-formats-to-fields)
111+
112+
**Related sample:** [Pivot 2. Defining fields formats](https://snippet.dhtmlx.com/77nc4j8v)

docs/api/config/headershape-property.md

+41-23
Original file line numberDiff line numberDiff line change
@@ -16,50 +16,68 @@ description: You can learn about the headerShape config in the documentation of
1616
headerShape?: {
1717
collapsible?: boolean,
1818
vertical?: boolean,
19-
template?: (label: string, field: string, subLabel?: string) => string
19+
template?: (label: string, field: string, subLabel?: string) => string,
20+
cellStyle?: (
21+
field: string,
22+
value: any,
23+
area: "rows"|"columns"|"values",
24+
method?: string,
25+
isTotal?: boolean)
26+
=> string,
2027
};
2128
~~~
2229

2330
### Parameters
2431

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:
32+
- `collapsible` - (optional) if set to **true**, dimension groups in the table are collapsible. It's set to **false** by default
33+
- `vertical` - (optional) if set to **true**, changes the text orientation in all headers from horizontal to vertical. The default value is **false**
34+
- `cellStyle` - (optional) a function that applies a custom style to a header cell. The function returns a name of css class and takes the following parameters:
35+
- `field` (string) - (required) a string representing the field name the cell corresponds to. For the header of the tree column the field is ""
36+
- `value` (string | number | date) - (required) the value of a cell
37+
- `area` - (required) a string indicating the area of the table where a cell resides ("rows", "columns" or "values" area)
38+
- `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
39+
- `isTotal` - (optional) defines whether a cell belongs to a total column
40+
- `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:
2841
~~~js
2942
template: (label, id, subLabel) =>
3043
label + (subLabel ? ` (${subLabel})` : "")
3144
~~~
3245

3346
## Example
3447

35-
~~~jsx {18-21}
36-
const table = new pivot.Pivot("#root", {
37-
fields,
38-
data: dataset,
48+
In the example below for the **values** fields the header will display the label, the method name (subLabel) and converts the result to lowercase (e.g., *profit (sum)*):
49+
50+
~~~jsx {3-6}
51+
new pivot.Pivot("#pivot", {
52+
data,
53+
headerShape: {
54+
// a custom template for header text
55+
template: (label, id, subLabel) => (label + (subLabel ? ` (${subLabel})` : "")).toLowerCase(),
56+
},
3957
config: {
40-
rows: ["studio", "genre"],
58+
rows: ["state", "product_type"],
4159
columns: [],
4260
values: [
4361
{
44-
field: "title",
45-
method: "count"
62+
field: "profit",
63+
method: "sum"
4664
},
4765
{
48-
field: "score",
49-
method: "max"
50-
}
51-
]
66+
field: "sales",
67+
method: "sum"
68+
},
69+
// other values
70+
],
5271
},
53-
headerShape: {
54-
vertical: true,
55-
template: (label, field, subLabel) => field + (subLabel ? ` (${subLabel})` : "")
56-
}
72+
fields,
5773
});
5874
~~~
5975

6076
**Related samples**:
61-
- [Pivot 2.0: Vertical orientation of text in grid headers](https://snippet.dhtmlx.com/4qroi8ka)
62-
- [Pivot 2.0: Collapsible columns](https://snippet.dhtmlx.com/pt2ljmcm)
63-
- [Pivot 2.0. Headers template](https://snippet.dhtmlx.com/g89r9ryw)
77+
- [Pivot 2. Vertical orientation of text in grid headers](https://snippet.dhtmlx.com/4qroi8ka)
78+
- [Pivot 2. Collapsible columns](https://snippet.dhtmlx.com/pt2ljmcm)
79+
- [Pivot 2. Adding сustom CSS for table and header cells](https://snippet.dhtmlx.com/nfdcs4i2)
6480

65-
**Related article**: [Configuration](/guides/configuration)
81+
**Related articles**:
82+
- [Configuration](/guides/configuration)
83+
- [Cell style](/guides/stylization/#cell-style)

docs/api/config/limits-property.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ const table = new pivot.Pivot("#root", {
5858
});
5959
~~~
6060

61-
**Related sample:** [Pivot 2.0. Data limits](https://snippet.dhtmlx.com/7ryns8oe)
61+
**Related sample:** [Pivot 2. Data limits](https://snippet.dhtmlx.com/7ryns8oe)

docs/api/config/methods-property.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,6 @@ const table = new pivot.Pivot("#root", {
158158
});
159159
~~~
160160

161-
**Related sample:** [Pivot 2.0: Custom math methods](https://snippet.dhtmlx.com/lv90d8q2)
161+
**Related sample:** [Pivot 2. Custom maths methods](https://snippet.dhtmlx.com/lv90d8q2)
162162

163163
**Related article**: [Applying maths methods](/guides/working-with-data#applying-maths-methods)

docs/api/config/predicates-property.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,4 @@ const table = new pivot.Pivot("#pivot", {
112112

113113
**Related article**: [Processing data with predicates](/guides/working-with-data#processing-data-with-predicates)
114114

115-
**Related sample**: [Pivot 2.0: Custom predicates](https://snippet.dhtmlx.com/mhymus00)
115+
**Related sample**: [Pivot 2. Custom predicates](https://snippet.dhtmlx.com/mhymus00)

docs/api/config/readonly-property.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ const table = new pivot.Pivot("#root", {
4949
});
5050
~~~
5151

52-
**Related sample:** [Pivot 2.0. Readonly mode](https://snippet.dhtmlx.com/0k0mvycv)
52+
**Related sample:** [Pivot 2. Readonly mode](https://snippet.dhtmlx.com/0k0mvycv)

docs/api/config/tableshape-property.md

+60-34
Original file line numberDiff line numberDiff line change
@@ -30,76 +30,102 @@ tableShape?: {
3030
sizes?: {
3131
rowHeight?: number,
3232
headerHeight?: number,
33-
colWidth?: number,
33+
columnWidth?: number,
3434
footerHeight?: number
3535
},
3636
tree?:boolean,
3737
cleanRows?: boolean,
3838
split?: {
39-
left?: boolean
40-
}
39+
left?: boolean,
40+
right?: boolean,
41+
},
42+
cellStyle?: (
43+
field: string,
44+
value: any,
45+
area: "rows"|"columns"|"values",
46+
method?: string,
47+
isTotal?: "row"|"column"|"both")
48+
=> string,
4149
};
4250
~~~
4351

4452
### Parameters
4553

4654
- `templates` - (optional) allows setting templates to a cell; it's an object where:
4755
- each key is a field id
48-
- the value is a function that returns a string and receives cell value and operation
49-
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.
50-
- `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 default value is {}. 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).
56+
- 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.
57+
- `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).
5158
- `sizes` - (optional) defines the following size parameters of the table:
52-
- `rowHeight` - (optional) the row height in the Pivot table in pixels; the default value is 34
59+
- `rowHeight` - (optional) the row height in the Pivot table in pixels. The default value is 34
5360
- `headerHeight` - (optional) the header height in pixels; the default value is 30
5461
- `footerHeight` - (optional) the footer height in pixels; the default value is 30
55-
- `colWidth` - (optional) the column width in pixels; the default value is 150
56-
- `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)
57-
- `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)
58-
- `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)
62+
- `columnWidth` - (optional) the column width in pixels; the default value is 150
63+
- `cellStyle` - (optional) a function that applies a custom style to a cell. The function has the next parameters:
64+
- `field` - (required) a string representing the field name for which the style is applied
65+
- `value` - (required) the value of the cell (the actual data for that particular row and column)
66+
- `area` - (required) a string indicating the area of the table where a cell resides ("rows", "columns" or "values" area)
67+
- `method` - (optional) a string that can represent the operation performed on a cell (e.g., "sum", "count", etc.)
68+
- `isTotal` - (optional) defines whether a cell belongs to a total row, total column, or both: "row"|"column"|"both
69+
The `cellStyle` function returns a string, which can be used as a CSS class name to apply specific styles to a cell.
70+
- `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)
71+
- `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)
72+
- `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)
5973
- `cleanRows` - (optional) if set to **true**, the duplicate values in scale columns are hidden in the table view. The default value is **false**
60-
- `split` - (optional) if set to **true**, 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.
74+
- `split` - (optional) allows freezing columns on the right or left depending on the parameter specified (refer to [Freezing columns](/guides/configuration/#freezing-columns)):
75+
- `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
76+
- `right` (boolean) - fixes total columns on the right; default value is **false**
6177

62-
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 left columns are not fixed during scroll.
78+
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.
6379

6480
## Example
6581

66-
In the example below we apply the template to the *score* values to display 2 digits after the decimal point for these values and we add the "€" sign to the *price* values.
82+
In the example below we apply the template to the *state* cells to show the combined name of a state (the full name and abbreviation).
6783

68-
~~~jsx {5-8}
69-
const templates = { price: (v) => (v ? "" + v : v),
70-
score: (v) => (v ? parseFloat(v).toFixed(2) : v) };
84+
~~~jsx {10-15}
85+
const states = {
86+
"California": "CA",
87+
"Colorado": "CO",
88+
"Connecticut": "CT",
89+
"Florida": "FL",
90+
// other values,
91+
};
7192

7293
const table = new pivot.Pivot("#root", {
7394
tableShape: {
74-
tree: true,
75-
templates
95+
templates: {
96+
// set a template to customize values of "state" cells
97+
state: v => v+ ` (${states[v]})`,
98+
}
7699
},
77100
fields,
78101
data,
79102
config: {
80-
rows: ["studio", "genre"],
103+
rows: ["state", "product_type"],
81104
columns: [],
82105
values: [
83106
{
84-
field: "title",
85-
method: "count"
107+
field: "profit",
108+
method: "sum"
86109
},
87110
{
88-
field: "score",
89-
method: "max"
111+
field: "sales",
112+
method: "sum"
90113
},
91-
{
92-
field: "price",
93-
method: "count"
94-
}
95-
]
96-
}
114+
// other values
115+
],
116+
},
117+
fields,
97118
});
98119
~~~
99120

100121
**Related samples:**
101-
- [Pivot 2.0: Tree mode](https://snippet.dhtmlx.com/6ylkoukn)
102-
- [Pivot 2.0. Frozen (fixed) columns](https://snippet.dhtmlx.com/lahf729o)
103-
- [Pivot 2.0. Set row, header, footer height and all columns width](https://snippet.dhtmlx.com/x46uyfy9)
104122

105-
**Related article**: [Configuration](/guides/configuration)
123+
- [Pivot 2. Tree mode](https://snippet.dhtmlx.com/6ylkoukn)
124+
- [Pivot 2. Frozen (fixed) columns](https://snippet.dhtmlx.com/lahf729o)
125+
- [Pivot 2. Set row, header, footer height and all columns width](https://snippet.dhtmlx.com/x46uyfy9)
126+
- [Pivot 2. Clean rows](https://snippet.dhtmlx.com/rwwhgv2w?tag=pivot)
127+
- [Pivot 2. Adding сustom CSS for table and header cells](https://snippet.dhtmlx.com/nfdcs4i2)
128+
129+
**Related articles**:
130+
- [Configuration](/guides/configuration)
131+
- [Cell style](/guides/stylization/#cell-style)

0 commit comments

Comments
 (0)