Skip to content

Commit 8559ddd

Browse files
committed
[update] data collection guides and related docs
1 parent 40e6cbc commit 8559ddd

File tree

9 files changed

+267
-128
lines changed

9 files changed

+267
-128
lines changed

docs/data_collection/api/datacollection_group_method.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ group(order: TGroupOrder[], config?: IGroupConfig): void;
4343
<tbody>
4444
<tr>
4545
<td><b>order</b></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 `(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>
4848
</tr>
4949
<tr>
5050
<td><b>config</b></td>

docs/data_collection/api/datacollection_remove_method.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ description: You can explore the remove method of DataCollection in the document
1616
@example:
1717
component.data.remove("2");
1818
//or
19-
component.data.remove([ "2", "4" ]);
19+
component.data.remove(["2", "4"]);
2020

2121
@descr:
2222

docs/grid/data_loading.md

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const grid = new dhx.Grid("grid_container", {
7373
columns: [
7474
// columns config
7575
],
76-
data: dataset
76+
// more options
7777
});
7878
~~~
7979

@@ -91,7 +91,12 @@ There are two ways to load data into Grid after its initialization:
9191
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:
9292

9393
~~~jsx
94-
const grid = new dhx.Grid("grid_container");
94+
const grid = new dhx.Grid("grid_container", {
95+
columns: [
96+
// columns config
97+
],
98+
// more options
99+
});
95100
grid.data.load("../common/dataset.json");
96101
~~~
97102

@@ -112,7 +117,12 @@ grid.data.load("/some/data").then(function(){
112117
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:
113118

114119
~~~jsx
115-
const grid = new dhx.Grid("grid_container");
120+
const grid = new dhx.Grid("grid_container", {
121+
columns: [
122+
// columns config
123+
],
124+
// more options
125+
});
116126
grid.data.parse(dataset);
117127
~~~
118128

@@ -126,7 +136,7 @@ Note that for loading data from a **CSV file** into a grid, you need to:
126136
Check the example below:
127137

128138
~~~jsx
129-
const grid = new dhx.Grid("grid", {
139+
const grid = new dhx.Grid("grid_container", {
130140
columns: [
131141
{ width: 150, id: "country", header: [{ text: "Country" }] },
132142
{ width: 150, id: "population", header: [{ text: "Population" }] },
@@ -148,7 +158,7 @@ grid.data.parse(csvData, csvDataDriver);
148158

149159
## Saving and restoring state
150160

151-
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.
152162
Each JSON object contains the configuration of a separate row.
153163

154164
~~~jsx
@@ -159,7 +169,12 @@ Then you can parse the data stored in the saved state array to a different grid.
159169

160170
~~~jsx
161171
// creating a new grid
162-
const grid2 = new dhx.Grid(document.body);
172+
const grid2 = new dhx.Grid("grid_container", {
173+
columns: [
174+
// columns config
175+
],
176+
// more options
177+
});
163178
// parsing the state of grid1 into grid2
164179
grid2.data.parse(state);
165180
~~~
@@ -186,7 +201,12 @@ new dhx.LazyDataProxy("https://docs.dhtmlx.com/suite/backend/lazyload", {
186201
- load data into Grid via the `load()` method of Data Collection and pass `lazyDataProxy` as a parameter of this method:
187202

188203
~~~jsx
189-
const grid = new dhx.Grid("grid_container");
204+
const grid = new dhx.Grid("grid_container", {
205+
columns: [
206+
// columns config
207+
],
208+
// more options
209+
});
190210
grid.data.load(lazyDataProxy);
191211
~~~
192212

docs/grid/usage.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,12 +1021,12 @@ The method takes the following parameters:
10211021
10221022
- `order` - an array that defines the order and configuration for data grouping. Each element in the array can be:
10231023
- 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
10251025
- an `IGroupOrder` object that has the following properties:
10261026
- `by` - the field name or a function for user-defined grouping
10271027
- `map` - (optional) an object for data aggregation in a group, where the keys are field names, and the values can be:
10281028
- 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`
10301030
- `summary` - (optional) specifies where the total row is rendered - at the `top` or at the `bottom` of the group
10311031
- `config` - (optional) the configuration of data grouping
10321032
- `showMissed` - (optional) specifies whether the elements that don't have the field for grouping should be displayed, *true* by default

docs/guides/datacollection/grouping_data.md

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,21 @@ The DataCollection API can be used for working with [data grouping in Grid](grid
1616

1717
## Grouping data
1818

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>
3634

3735
There are several examples of grouping Grid data via the `group()` method of DataCollection:
3836

docs/guides/datacollection/loading_data.md

Lines changed: 106 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ description: You can learn how to load and save data with DataCollection in the
66

77
# Loading and saving data
88

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.
1010

1111
:::info
1212
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
2727
Data loading is asynchronous, so you need to wrap any after-loading code into a promise:
2828

2929
~~~jsx
30-
component.data.load(url).then(function(){
30+
component.data.load(url).then(function () {
3131
// do something after load
3232
});
3333
~~~
@@ -36,7 +36,7 @@ or
3636

3737
~~~jsx
3838
component.data.load(url);
39-
component.data.loadData.then(function(){
39+
component.data.loadData.then(function () {
4040
// do something after load
4141
});
4242
// loadData executes a callback function after an asynchronous
@@ -74,6 +74,70 @@ dataview.data.parse(dataset);
7474

7575
**Related sample**: [Data. Parse](https://snippet.dhtmlx.com/0zrxtmvi)
7676

77+
## Dynamic loading
78+
79+
:::tip pro version only
80+
This functionality requires PRO version of the DHTMLX Grid (or DHTMLX Suite) package
81+
:::
82+
83+
You can load data from the server into DHTMLX Grid or DHTMLX List dynamically. It means that data is loaded
84+
partially, on demand, and only those records that are in the visible area are rendered.
85+
86+
To use this functionality, you should take the following steps:
87+
88+
- initialize the `LazyDataProxy` helper as described in the [Dynamic Loading](helpers/lazydataproxy.md) article:
89+
90+
~~~jsx
91+
new dhx.LazyDataProxy("https://docs.dhtmlx.com/suite/backend/lazyload", {
92+
limit: 30,
93+
prepare: 5,
94+
delay: 150,
95+
from: 0
96+
});
97+
~~~
98+
99+
:::info
100+
To enable dynamic rendering of List items, switch on the `virtual` property of the component:
101+
102+
~~~jsx
103+
const list = new dhx.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+
const grid = new dhx.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+
const list = new dhx.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+
77141
## Checking whether data is loaded
78142

79143
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
84148

85149
The method takes the following parameters:
86150

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
89153

90154
and returns `true`, if a range of data is loaded; otherwise, `false`.
91155

@@ -97,7 +161,7 @@ component.data.isDataLoaded();
97161

98162
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:
99163

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")
101165

102166
and returns serialized data for each item of the component either as an array of JSON objects or as a CSV/XML string.
103167

@@ -113,12 +177,44 @@ After you've saved a component's state, you can send the data stored in the save
113177

114178
~~~jsx
115179
// creating a new grid
116-
const grid2 = new dhx.Grid(document.body);
180+
const grid2 = new dhx.Grid("grid_container", {
181+
columns: [
182+
// columns config
183+
],
184+
// more options
185+
});
117186
// parsing the state of grid1 into grid2
118187
grid2.data.parse(state);
119188
~~~
120189

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+
const proxy = new dhx.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:
208+
209+
~~~jsx
210+
const dataCollection = new dhx.DataCollection();
211+
const proxy = new dhx.DataProxy("https://myCustomUrl.com");
212+
dataCollection.load(proxy);
213+
~~~
214+
215+
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
122218

123219
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:
124220

@@ -144,15 +240,15 @@ Data saving is asynchronous, so you need to return a promise - the result of the
144240
~~~jsx
145241
const data = new DataCollection();
146242
data.save(loader);
147-
return data.saveData.then(function(){
243+
return data.saveData.then(function () {
148244
// now your data is saved
149245
});
150246
~~~
151247

152248
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*.
153249

154250
~~~jsx
155-
grid.data.saveData.then(function(){
251+
grid.data.saveData.then(function () {
156252
console.log(grid.data.isSaved());
157253
});
158254
~~~

0 commit comments

Comments
 (0)