You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<td> (<i>array</i>) an array that defines the order and configuration for data grouping. Each element in the array can be:<ul><li>a string that represents a grouping field</li><li>a function `(i: IDataItem) => string` for dynamic defining of a group</li><li>an `IGroupOrder` object that has the following properties:<ul><li><b>`by: string | function`</b> - the field name or a function for user-defined grouping</li><li><b>`map?: object`</b> - optional, an object for data aggregation in a group, where the keys are field names, and the values can be:
47
-
<ul><li>a tuple `[string, TAggregate]` that specifies the field and the aggregation type ("sum", "count", "min", "max", "avg") from the <a href="../../../helpers/data_calculation_functions/">`dhx.methods`</a> helper</li><li> a user-defined aggregation function `(i: IDataItem[]) => string | number`</li></ul></li><li><b>`summary?: string`</b> - optional, specifies where the total row is rendered - at the `top` or at the `bottom` of the group </li></ul></li></ul></td>
46
+
<td> (<i>array</i>) an array that defines the order and configuration for data grouping. Each element in the array can be:<ul><li>a string that represents a grouping field</li><li>a function `(item: IDataItem) => string` for dynamic defining of a group</li><li>an `IGroupOrder` object that has the following properties:<ul><li><b>`by: string | function`</b> - the field name or a function for user-defined grouping</li><li><b>`map?: object`</b> - optional, an object for data aggregation in a group, where the keys are field names, and the values can be:
47
+
<ul><li>a tuple `[string, TAggregate]` that specifies the field and the aggregation type ("sum", "count", "min", "max", "avg") from the <a href="../../../helpers/data_calculation_functions/">`dhx.methods`</a> helper</li><li> a user-defined aggregation function `(item: IDataItem[]) => string | number`</li></ul></li><li><b>`summary?: string`</b> - optional, specifies where the total row is rendered - at the `top` or at the `bottom` of the group </li></ul></li></ul></td>
Copy file name to clipboardExpand all lines: docs/grid/data_loading.md
+27-7Lines changed: 27 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -73,7 +73,7 @@ const grid = new dhx.Grid("grid_container", {
73
73
columns: [
74
74
// columns config
75
75
],
76
-
data: dataset
76
+
// more options
77
77
});
78
78
~~~
79
79
@@ -91,7 +91,12 @@ There are two ways to load data into Grid after its initialization:
91
91
To load data from an external file, make use of the **load()** method of [Data Collection](data_collection.md). It takes the URL of the file with data as a parameter:
To load data from a local data source, use the `parse()` method of [Data Collection](data_collection.md). Pass [a predefined data set](#preparing-data-set) as a parameter of this method:
113
118
114
119
~~~jsx
115
-
constgrid=newdhx.Grid("grid_container");
120
+
constgrid=newdhx.Grid("grid_container", {
121
+
columns: [
122
+
// columns config
123
+
],
124
+
// more options
125
+
});
116
126
grid.data.parse(dataset);
117
127
~~~
118
128
@@ -126,7 +136,7 @@ Note that for loading data from a **CSV file** into a grid, you need to:
To save the current state of a grid, use the **serialize()** method of [Data Collection](data_collection.md). It converts the data of a grid into an array of JSON objects.
161
+
To save the current state of a grid, use the `serialize()` method of [Data Collection](data_collection.md). It converts the data of a grid into an array of JSON objects.
152
162
Each JSON object contains the configuration of a separate row.
153
163
154
164
~~~jsx
@@ -159,7 +169,12 @@ Then you can parse the data stored in the saved state array to a different grid.
159
169
160
170
~~~jsx
161
171
// creating a new grid
162
-
constgrid2=newdhx.Grid(document.body);
172
+
constgrid2=newdhx.Grid("grid_container", {
173
+
columns: [
174
+
// columns config
175
+
],
176
+
// more options
177
+
});
163
178
// parsing the state of grid1 into grid2
164
179
grid2.data.parse(state);
165
180
~~~
@@ -186,7 +201,12 @@ new dhx.LazyDataProxy("https://docs.dhtmlx.com/suite/backend/lazyload", {
186
201
- load data into Grid via the `load()` method of Data Collection and pass `lazyDataProxy` as a parameter of this method:
Copy file name to clipboardExpand all lines: docs/grid/usage.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1021,12 +1021,12 @@ The method takes the following parameters:
1021
1021
1022
1022
- `order` - an array that defines the order and configuration for data grouping. Each element in the array can be:
1023
1023
- a string that represents a grouping field
1024
-
- a function `(i: IDataItem) => string` for dynamic defining of a group
1024
+
- a function `(item: IDataItem) => string` for dynamic defining of a group
1025
1025
- an `IGroupOrder` object that has the following properties:
1026
1026
- `by` - the field name or a function for user-defined grouping
1027
1027
- `map` - (optional) an object for data aggregation in a group, where the keys are field names, and the values can be:
1028
1028
- a tuple `[string, TAggregate]` that specifies the field and the aggregation type ("sum", "count", "min", "max", "avg") from the [`dhx.methods`](helpers/data_calculation_functions.md) helper
1029
-
- a user-defined aggregation function `(i: IDataItem[]) => string | number`
1029
+
- a user-defined aggregation function `(item: IDataItem[]) => string | number`
1030
1030
- `summary` - (optional) specifies where the total row is rendered - at the `top` or at the `bottom` of the group
1031
1031
- `config` - (optional) the configuration of data grouping
1032
1032
- `showMissed` - (optional) specifies whether the elements that don't have the field for grouping should be displayed, *true* by default
Copy file name to clipboardExpand all lines: docs/guides/datacollection/grouping_data.md
+15-17Lines changed: 15 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,23 +16,21 @@ The DataCollection API can be used for working with [data grouping in Grid](grid
16
16
17
17
## Grouping data
18
18
19
-
The [`group()`](data_collection/api/datacollection_group_method.md) method of DataCollection groups data in a collection that has a plain tree-like structure according to the specified order and additional configuration. The method takes the following parameters:
20
-
21
-
-`order` - an array that defines the order and configuration for data grouping. Each element in the array can be:
22
-
- a string that represents a grouping field
23
-
- a function `(i: IDataItem) => string` for dynamic defining of a group
24
-
- an `IGroupOrder` object that has the following properties:
25
-
- `by` - the field name or a function for user-defined grouping
26
-
- `map` - (optional) an object for data aggregation in a group, where the keys are field names, and the values can be:
27
-
- a tuple `[string, TAggregate]` that specifies the field and the aggregation type ("sum", "count", "min", "max", "avg") from the [`dhx.methods`](helpers/data_calculation_functions.md) helper
28
-
- a user-defined aggregation function `(i: IDataItem[]) => string | number`
29
-
- `summary` - (optional) specifies where the total row is rendered - at the `top` or at the `bottom` of the group
30
-
-`config` - (optional) the configuration of data grouping
31
-
-`showMissed` - (optional) specifies whether the elements that don't have the field for grouping should be displayed, *true* by default
32
-
- if set to *true*, the rows that don't have values for grouping are rendered row by row after all the data
33
-
- if a *string* value is set, e.g. "Missed", the rows that don't have values for grouping are rendered as a separate group the name of which will have the specified string value. This group will be rendered as the last one
34
-
- if set to *false*, the rows that don't suit the grouping criteria won't be rendered
35
-
-`field` - (optional) the group field name, *"group"* by default
19
+
The [`group()`](data_collection/api/datacollection_group_method.md) method of DataCollection groups data in a collection that has a flat tree structure according to the specified order and additional configuration. The method takes the following parameters:
20
+
21
+
<table>
22
+
<tbody>
23
+
<tr>
24
+
<td><b>order</b></td>
25
+
<td> (<i>array</i>) an array that defines the order and configuration for data grouping. Each element in the array can be:<ul><li>a string that represents a grouping field</li><li>a function `(item: IDataItem) => string` for dynamic defining of a group</li><li>an `IGroupOrder` object that has the following properties:<ul><li><b>`by: string | function`</b> - the field name or a function for user-defined grouping</li><li><b>`map?: object`</b> - optional, an object for data aggregation in a group, where the keys are field names, and the values can be:
26
+
<ul><li>a tuple `[string, TAggregate]` that specifies the field and the aggregation type ("sum", "count", "min", "max", "avg") from the <a href="../../../helpers/data_calculation_functions/">`dhx.methods`</a> helper</li><li> a user-defined aggregation function `(item: IDataItem[]) => string | number`</li></ul></li><li><b>`summary?: string`</b> - optional, specifies where the total row is rendered - at the `top` or at the `bottom` of the group </li></ul></li></ul></td>
27
+
</tr>
28
+
<tr>
29
+
<td><b>config</b></td>
30
+
<td>(<i>object</i>) optional, the configuration of data grouping. The configuration object may include the following properties:<ul><li><b>`showMissed?: boolean | string`</b> - optional, specifies whether the elements that don't have the field for grouping should be displayed, *true* by default<ul><li>if set to *true*, the rows that don't have values for grouping are rendered row by row after all the data</li><li>if a *string* value is set, e.g. "Missed", the rows that don't have values for grouping are rendered as a separate group the name of which will have the specified string value. This group will be rendered as the last one</li><li>if set to *false*, the rows that don't suit the grouping criteria won't be rendered</li></ul></li><li><b>`field?: string`</b> - optional, the group field name, *"group"* by default</li></ul></td>
31
+
</tr>
32
+
</tbody>
33
+
</table>
36
34
37
35
There are several examples of grouping Grid data via the `group()` method of DataCollection:
@@ -6,7 +6,7 @@ description: You can learn how to load and save data with DataCollection in the
6
6
7
7
# Loading and saving data
8
8
9
-
You can load data into a component from an external file or from a local data source via the DataCollection API. It also allows saving the state of a component and sending it to a different component, as well as saving changes made in the data to the server side.
9
+
You can load data into a component from an external file, a local data source or the server side via the DataCollection API. It also allows saving the state of a component and sending it to a different component, as well as saving changes made in the data to the server side.
10
10
11
11
:::info
12
12
Please note that if you specify the `id` fields in the loaded data collection, their values should be **unique**. You can also omit the `id` fields in the data collection. In this case they will be generated automatically.
@@ -27,7 +27,7 @@ The component will make an AJAX call and expect the remote URL to provide valid
27
27
Data loading is asynchronous, so you need to wrap any after-loading code into a promise:
28
28
29
29
~~~jsx
30
-
component.data.load(url).then(function(){
30
+
component.data.load(url).then(function () {
31
31
// do something after load
32
32
});
33
33
~~~
@@ -36,7 +36,7 @@ or
36
36
37
37
~~~jsx
38
38
component.data.load(url);
39
-
component.data.loadData.then(function(){
39
+
component.data.loadData.then(function () {
40
40
// do something after load
41
41
});
42
42
// loadData executes a callback function after an asynchronous
To enable dynamic rendering of List items, switch on the `virtual` property of the component:
101
+
102
+
~~~jsx
103
+
constlist=newdhx.List("list_container", {
104
+
virtual:true
105
+
});
106
+
~~~
107
+
:::
108
+
109
+
- load data into Grid or List via the `load()` method of Data Collection and pass `lazyDataProxy` as a parameter of this method:
110
+
111
+
~~~jsx
112
+
// for Grid
113
+
constgrid=newdhx.Grid("grid_container", {
114
+
columns: [
115
+
// columns config
116
+
],
117
+
// more options
118
+
});
119
+
grid.data.load(lazyDataProxy);
120
+
~~~
121
+
122
+
**Related sample**: [External data lazy load](https://snippet.dhtmlx.com/grid_lazy_loading)
123
+
124
+
~~~jsx
125
+
// for List
126
+
constlist=newdhx.List("list_container");
127
+
list.data.load(lazyDataProxy);
128
+
~~~
129
+
130
+
**Related sample**: [List. External data lazy loading](https://snippet.dhtmlx.com/list_lazy_loading)
131
+
132
+
Read the related guides for detailed information:
133
+
134
+
-[dynamic loading in Grid](grid/data_loading.md#dynamic-loading)
135
+
-[dynamic loading in List](list/load_data.md#dynamic-loading)
136
+
137
+
:::info
138
+
The `sort()` method of Data Collection will not work until all data are loaded into Grid/List. Note that for correct work of lazy loading, you should send all changes in Data Collection to the server at the proper time.
139
+
:::
140
+
77
141
## Checking whether data is loaded
78
142
79
143
You can check whether the specified data range is loaded from the server using the [`isDataLoaded()`](data_collection/api/datacollection_isdataloaded_method.md) method of [DataCollection](data_collection.md).
@@ -84,8 +148,8 @@ The method works with the [Dynamic loading](helpers/lazydataproxy.md) functional
84
148
85
149
The method takes the following parameters:
86
150
87
-
-`from: number` - optional, the index of the first element of the data range to be checked
88
-
-`to: number` - optional, the index of the last element of the data range to be checked
151
+
-`from?: number` - optional, the index of the first element of the data range to be checked
152
+
-`to?: number` - optional, the index of the last element of the data range to be checked
89
153
90
154
and returns `true`, if a range of data is loaded; otherwise, `false`.
91
155
@@ -97,7 +161,7 @@ component.data.isDataLoaded();
97
161
98
162
To save the current state of a component, use the [`serialize()`](data_collection/api/datacollection_serialize_method.md) method of Data Collection. The method is used to serialize data into the JSON, XML or CSV format. It takes the following parameter:
99
163
100
-
-`driver: string` - optional, the format that the data will be serialized into ("json" (default), "csv", "xml")
164
+
-`driver?: string` - optional, the format that the data will be serialized into ("json" (default), "csv", "xml")
101
165
102
166
and returns serialized data for each item of the component either as an array of JSON objects or as a CSV/XML string.
103
167
@@ -113,12 +177,44 @@ After you've saved a component's state, you can send the data stored in the save
113
177
114
178
~~~jsx
115
179
// creating a new grid
116
-
constgrid2=newdhx.Grid(document.body);
180
+
constgrid2=newdhx.Grid("grid_container", {
181
+
columns: [
182
+
// columns config
183
+
],
184
+
// more options
185
+
});
117
186
// parsing the state of grid1 into grid2
118
187
grid2.data.parse(state);
119
188
~~~
120
189
121
-
## Saving data changes to the server side
190
+
## Working with the server side
191
+
192
+
To provide communication with the server side, you can use the [`DataProxy`](data_proxy.md) helper. Using this helper you can create a custom URL and assign it to a variable to simplify work with the server-side backend. For example:
193
+
194
+
~~~jsx
195
+
constproxy=newdhx.DataProxy("someUrl", {
196
+
// config options
197
+
});
198
+
~~~
199
+
200
+
The `dhx.DataProxy` helper takes two parameters:
201
+
202
+
-`url: string` - the external URL
203
+
-`params?: object` - optional, a set of custom parameters to be sent to the server with a request
204
+
205
+
### Loading data from the server side
206
+
207
+
You can apply a custom URL configured by the DataProxy helper to DataCollection while loading data with the [`load()`](data_collection/api/datacollection_load_method.md) method. As a parameter, pass the DataProxy with the configured URL:
The same as with [loading data from an external file](#loading-data-from-an-external-file), the component will make an AJAX call and expect the remote URL to provide valid JSON data.
216
+
217
+
### Saving data changes to the server side
122
218
123
219
You can save changes made in the data to the server side using the [`save()`](data_collection/api/datacollection_save_method.md) method of Data Collection. The method takes the following parameter:
124
220
@@ -144,15 +240,15 @@ Data saving is asynchronous, so you need to return a promise - the result of the
144
240
~~~jsx
145
241
constdata=newDataCollection();
146
242
data.save(loader);
147
-
returndata.saveData.then(function(){
243
+
returndata.saveData.then(function () {
148
244
// now your data is saved
149
245
});
150
246
~~~
151
247
152
248
Use the [`isSaved()`](data_collection/api/datacollection_issaved_method.md) method to check whether the changes are saved. The method returns *true*, if the changes are saved, otherwise, *false*.
0 commit comments