Skip to content

Commit 7e212f9

Browse files
committed
[update] grid multi-sorting guide and api
1 parent 4b13f36 commit 7e212f9

File tree

7 files changed

+205
-104
lines changed

7 files changed

+205
-104
lines changed

docs/data_collection/api/datacollection_getsortingstates_method.md

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ The method allows getting the result of sorting data by multiple columns.
1616

1717
~~~jsx
1818
interface ISortingState {
19-
by?: string | number, // the id of a data field (a column of Grid) to sort by
20-
dir?: "asc" | "desc", // the direction of sorting: "asc" or "desc"
21-
as?: (a) => any, // a custom function of converting values before comparing
22-
rule?: (a, b) => number, // a custom sorting function
23-
smartSorting?: boolean // (if can be applied) specifies whether a sorting rule should be applied each time after changing the data set
19+
by?: string | number,
20+
dir?: "asc" | "desc",
21+
as?: (a) => any,
22+
rule?: (a, b) => number,
23+
smartSorting?: boolean
2424
}
2525

2626
getSortingStates(): ISortingState[];
@@ -34,13 +34,32 @@ const state = grid.data.getSortingStates();
3434
// -> [{by: "country", dir: "desc"}, {by: "population", dir: "desc"}]
3535

3636
@descr:
37-
The return array contains objects with the following properties:
37+
The array returned by the method contains objects with the following properties:
3838

39-
- `by` - (*string|number*) the id of a data field (a column of Grid) to sort by
40-
- `dir` - (*"asc"|"desc"*) the direction of sorting: "asc" or "desc"
41-
- `as` - (*function*) a custom function of converting values before comparing
42-
- `rule` - (*function*) a custom sorting function
43-
- `smartSorting` - (*boolean*) (if can be applied) specifies whether a sorting rule should be applied each time after changing the data set
39+
<table>
40+
<tbody>
41+
<tr>
42+
<td><b>by</b></td>
43+
<td>(<i>string | number</i>) the id of a data field (a column of Grid) to sort by</td>
44+
</tr>
45+
<tr>
46+
<td><b>dir</b></td>
47+
<td>(<i>string</i>) the direction of sorting: "asc" or "desc"</td>
48+
</tr>
49+
<tr>
50+
<td><b>as</b></td>
51+
<td>(<i>function</i>) a custom function of converting values before comparing</td>
52+
</tr>
53+
<tr>
54+
<td><b>rule</b></td>
55+
<td>(<i>function</i>) a custom sorting function</td>
56+
</tr>
57+
<tr>
58+
<td><b>smartSorting</b></td>
59+
<td>(<i>boolean</i>) (if applied) specifies whether a sorting rule should be applied each time after changing the data set</td>
60+
</tr>
61+
</tbody>
62+
</table>
4463

4564
@changelog:
4665
added in v9.1

docs/data_collection/index.md

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,41 @@ description: You can have an overview of DataCollection in the documentation of
99
A set of APIs that allow you to work with data of a component. Applicable to Chart, Combobox, DataView, Grid, List.
1010
## Methods
1111

12-
| Name | Description |
13-
| ----------------------------------------------- | ------------------------------------------------------ |
14-
| [](api/datacollection_add_method.md) | @getshort(api/datacollection_add_method.md) |
15-
| [](api/datacollection_changeid_method.md) | @getshort(api/datacollection_changeid_method.md) |
16-
| [](api/datacollection_copy_method.md) | @getshort(api/datacollection_copy_method.md) |
17-
| [](api/datacollection_exists_method.md) | @getshort(api/datacollection_exists_method.md) |
18-
| [](api/datacollection_filter_method.md) | @getshort(api/datacollection_filter_method.md) |
19-
| [](api/datacollection_find_method.md) | @getshort(api/datacollection_find_method.md) |
20-
| [](api/datacollection_findall_method.md) | @getshort(api/datacollection_findall_method.md) |
21-
| [](api/datacollection_foreach_method.md) | @getshort(api/datacollection_foreach_method.md) |
22-
| [](api/datacollection_getfilters_method.md) | @getshort(api/datacollection_getfilters_method.md) |
23-
| [](api/datacollection_getid_method.md) | @getshort(api/datacollection_getid_method.md) |
24-
| [](api/datacollection_getindex_method.md) | @getshort(api/datacollection_getindex_method.md) |
25-
| [](api/datacollection_getinitialdata_method.md) | @getshort(api/datacollection_getinitialdata_method.md) |
26-
| [](api/datacollection_getitem_method.md) | @getshort(api/datacollection_getitem_method.md) |
27-
| [](api/datacollection_getlength_method.md) | @getshort(api/datacollection_getlength_method.md) |
28-
| [](api/datacollection_group_method.md) | @getshort(api/datacollection_group_method.md) |
29-
| [](api/datacollection_isdataloaded_method.md) | @getshort(api/datacollection_isdataloaded_method.md) |
30-
| [](api/datacollection_isgrouped_method.md) | @getshort(api/datacollection_isgrouped_method.md) |
31-
| [](api/datacollection_issaved_method.md) | @getshort(api/datacollection_issaved_method.md) |
32-
| [](api/datacollection_load_method.md) | @getshort(api/datacollection_load_method.md) |
33-
| [](api/datacollection_map_method.md) | @getshort(api/datacollection_map_method.md) |
34-
| [](api/datacollection_maprange_method.md) | @getshort(api/datacollection_maprange_method.md) |
35-
| [](api/datacollection_move_method.md) | @getshort(api/datacollection_move_method.md) |
36-
| [](api/datacollection_parse_method.md) | @getshort(api/datacollection_parse_method.md) |
37-
| [](api/datacollection_reduce_method.md) | @getshort(api/datacollection_reduce_method.md) |
38-
| [](api/datacollection_remove_method.md) | @getshort(api/datacollection_remove_method.md) |
39-
| [](api/datacollection_removeall_method.md) | @getshort(api/datacollection_removeall_method.md) |
40-
| [](api/datacollection_resetfilter_method.md) | @getshort(api/datacollection_resetfilter_method.md) |
41-
| [](api/datacollection_save_method.md) | @getshort(api/datacollection_save_method.md) |
42-
| [](api/datacollection_serialize_method.md) | @getshort(api/datacollection_serialize_method.md) |
43-
| [](api/datacollection_sort_method.md) | @getshort(api/datacollection_sort_method.md) |
44-
| [](api/datacollection_ungroup_method.md) | @getshort(api/datacollection_ungroup_method.md) |
45-
| [](api/datacollection_update_method.md) | @getshort(api/datacollection_update_method.md) |
12+
| Name | Description |
13+
| ------------------------------------------------- | ------------------------------------------------------- |
14+
| [](api/datacollection_add_method.md) | @getshort(api/datacollection_add_method.md) |
15+
| [](api/datacollection_changeid_method.md) | @getshort(api/datacollection_changeid_method.md) |
16+
| [](api/datacollection_copy_method.md) | @getshort(api/datacollection_copy_method.md) |
17+
| [](api/datacollection_exists_method.md) | @getshort(api/datacollection_exists_method.md) |
18+
| [](api/datacollection_filter_method.md) | @getshort(api/datacollection_filter_method.md) |
19+
| [](api/datacollection_find_method.md) | @getshort(api/datacollection_find_method.md) |
20+
| [](api/datacollection_findall_method.md) | @getshort(api/datacollection_findall_method.md) |
21+
| [](api/datacollection_foreach_method.md) | @getshort(api/datacollection_foreach_method.md) |
22+
| [](api/datacollection_getfilters_method.md) | @getshort(api/datacollection_getfilters_method.md) |
23+
| [](api/datacollection_getid_method.md) | @getshort(api/datacollection_getid_method.md) |
24+
| [](api/datacollection_getindex_method.md) | @getshort(api/datacollection_getindex_method.md) |
25+
| [](api/datacollection_getinitialdata_method.md) | @getshort(api/datacollection_getinitialdata_method.md) |
26+
| [](api/datacollection_getitem_method.md) | @getshort(api/datacollection_getitem_method.md) |
27+
| [](api/datacollection_getlength_method.md) | @getshort(api/datacollection_getlength_method.md) |
28+
| [](api/datacollection_getsortingstates_method.md) | @getshort(api/datacollection_getsortingstates_method.md)|
29+
| [](api/datacollection_group_method.md) | @getshort(api/datacollection_group_method.md) |
30+
| [](api/datacollection_isdataloaded_method.md) | @getshort(api/datacollection_isdataloaded_method.md) |
31+
| [](api/datacollection_isgrouped_method.md) | @getshort(api/datacollection_isgrouped_method.md) |
32+
| [](api/datacollection_issaved_method.md) | @getshort(api/datacollection_issaved_method.md) |
33+
| [](api/datacollection_load_method.md) | @getshort(api/datacollection_load_method.md) |
34+
| [](api/datacollection_map_method.md) | @getshort(api/datacollection_map_method.md) |
35+
| [](api/datacollection_maprange_method.md) | @getshort(api/datacollection_maprange_method.md) |
36+
| [](api/datacollection_move_method.md) | @getshort(api/datacollection_move_method.md) |
37+
| [](api/datacollection_parse_method.md) | @getshort(api/datacollection_parse_method.md) |
38+
| [](api/datacollection_reduce_method.md) | @getshort(api/datacollection_reduce_method.md) |
39+
| [](api/datacollection_remove_method.md) | @getshort(api/datacollection_remove_method.md) |
40+
| [](api/datacollection_removeall_method.md) | @getshort(api/datacollection_removeall_method.md) |
41+
| [](api/datacollection_resetfilter_method.md) | @getshort(api/datacollection_resetfilter_method.md) |
42+
| [](api/datacollection_save_method.md) | @getshort(api/datacollection_save_method.md) |
43+
| [](api/datacollection_serialize_method.md) | @getshort(api/datacollection_serialize_method.md) |
44+
| [](api/datacollection_sort_method.md) | @getshort(api/datacollection_sort_method.md) |
45+
| [](api/datacollection_ungroup_method.md) | @getshort(api/datacollection_ungroup_method.md) |
46+
| [](api/datacollection_update_method.md) | @getshort(api/datacollection_update_method.md) |
4647

4748
## Events
4849

docs/grid/api/grid_multisort_config.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ const grid = new dhx.Grid("grid_container", {
2828
@descr:
2929

3030
**Related sample**: [Grid. Sorting by multiple columns (multisorting)](https://snippet.dhtmlx.com/4ej0i3qi)
31+
32+
**Related article**: [Sorting by multiple columns](grid/usage.md#sorting-by-multiple-columns)

docs/grid/usage.md

Lines changed: 72 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ You can filter grid data by the specified criteria with the help of the `filter(
273273
</tr>
274274
<tr>
275275
<td><b>config</b></td>
276-
<td>(<i>object</i>) optional, an object with the following properties:<ul><li><b>id</b> (<i>string</i>) - optional, the id of the filter</li><li><b>add</b> (<i>boolean</i>) defines whether each next filtering will be applied to the already filtered data (<i>true</i>), or to the initial data (<i>false</i>, default)</li><li><b>permanent</b> (<i>boolean</i>) - optional, <i>true</i> to make the current filter permanent. It will be applied even if the next filtering doesn't have the <b>add:true</b> property in its configuration object. Such a filter can be removed just with the resetFilter() method</li></ul></td>
276+
<td>(<i>object</i>) optional, an object with the following properties:<ul><li><b>id</b> - (<i>string</i>) optional, the id of the filter</li><li><b>add</b> - (<i>boolean</i>) defines whether each next filtering will be applied to the already filtered data (<i>true</i>), or to the initial data (<i>false</i>, default)</li><li><b>permanent</b> - (<i>boolean</i>) optional, <i>true</i> to make the current filter permanent. It will be applied even if the next filtering doesn't have the <b>add:true</b> property in its configuration object. Such a filter can be removed just with the resetFilter() method</li></ul></td>
277277
</tr>
278278
</tbody>
279279
</table>
@@ -314,7 +314,7 @@ It is possible to sort data in the grid via the `sort()` method of [DataCollecti
314314
<tbody>
315315
<tr>
316316
<td><b>rule</b></td>
317-
<td>(<i>object</i>) an object with parameters for sorting. It can take the following attributes:<ul><li><b>by</b> (<i>string | number</i>) the id of a column</li><li><b>dir</b> (<i>string</i>) the direction of sorting "asc" or "desc"</li><li><b>as</b> (<i>function</i>) a function that specifies the type to sort data as</li><li><b>rule</b> (<i>function</i>) optional, a sorting rule; the function must have two parameters and return a number (-1,0,1)</li></ul></td>
317+
<td>(<i>object</i>) an object with parameters for sorting. It can take the following attributes:<ul><li><b>by</b> - (<i>string | number</i>) the id of a column</li><li><b>dir</b> - (<i>string</i>) the direction of sorting "asc" or "desc"</li><li><b>as</b> - (<i>function</i>) a function that specifies the type to sort data as</li><li><b>rule</b> - (<i>function</i>) optional, a sorting rule; the function must have two parameters and return a number (-1,0,1)</li></ul></td>
318318
</tr>
319319
<tr>
320320
<td><b>config</b></td>
@@ -324,7 +324,7 @@ It is possible to sort data in the grid via the `sort()` method of [DataCollecti
324324
</table>
325325
<br/>
326326

327-
~~~js
327+
~~~jsx
328328
grid.data.sort({
329329
by:"a",
330330
dir:"desc",
@@ -339,34 +339,92 @@ grid.data.sort({
339339

340340
**Related sample**: [Grid. Sorting](https://snippet.dhtmlx.com/81dmbdfd)
341341

342+
#### Sorting by multiple columns
343+
344+
:::tip pro version only
345+
The described functionality requires PRO version of the DHTMLX Grid (or DHTMLX Suite) package.
346+
:::
347+
348+
You can sort Grid by multiple columns simultaneously. The multi-sorting ability is enabled by default. If you need to disable it, set the [`multiSort`](grid/api/grid_multisort_config.md) Grid property to *false*.
349+
350+
~~~jsx
351+
const grid = new dhx.Grid("grid_container", {
352+
columns: [
353+
// columns config
354+
],
355+
multiSort: false,
356+
data: dataset
357+
});
358+
~~~
359+
360+
**Related sample**: [Grid. Sorting by multiple columns (multisorting)](https://snippet.dhtmlx.com/4ej0i3qi)
361+
362+
It is also possible to apply multi-sorting to [the grouped data](grid/usage.md#grouping-data). Check the example below:
363+
364+
~~~jsx
365+
const grid = new dhx.Grid("grid_container", {
366+
columns: [
367+
// columns config
368+
],
369+
editable: true,
370+
group: {
371+
order: ["animal_type"] // group by the `animal_type` field
372+
},
373+
groupable: true, // enables grouping functionality, false by default
374+
data: dataset
375+
});
376+
377+
grid.data.sort({ by: "volunteer_name", dir: "desc" }, { smartSorting: true });
378+
grid.data.sort({ by: "task_status", dir: "asc" });
379+
grid.data.sort({ by: "animal_type", dir: "asc" });
380+
~~~
381+
382+
**Related sample**: [Grid. Grouping with sorting by multiple columns (multisorting)](https://snippet.dhtmlx.com/786zr190)
383+
342384
#### Custom sorting
343385

344-
You can also specify the **rule** attribute in a passed object instead of the default ones and set a custom function for sorting. For example:
386+
You can also specify the `rule` attribute in a passed object instead of the default ones and set a custom function for sorting. For example:
345387

346-
~~~js
388+
~~~jsx
347389
grid.data.sort({
348390
rule: (a, b) => a.id > b.id ? 1 : (a.id < b.id ? -1 : 0)
349391
});
350392
~~~
351393

352394
#### Getting the sorting state
353395

354-
To get the current state of sorting data in Grid, use the [`getSortingStates()`](data_collection/api/datacollection_getsortingstates_method.md) method of DataCollection. The method returns an object with the following properties:
355-
356-
- `by` - (*string|number*) the id of a data field (a column of Grid) to sort by
357-
- `dir` - (*"asc"|"desc"*) the direction of sorting: "asc" or "desc"
358-
- `as` - (*function*) a custom function of converting values before comparing
359-
- `rule` - (*function*) a custom sorting function
360-
- `smartSorting` - (*boolean*) (if can be applied) specifies whether a sorting rule should be applied each time after changing the data set
396+
To get the current state of sorting data in Grid, use the [`getSortingStates()`](data_collection/api/datacollection_getsortingstates_method.md) method of DataCollection. The method allows getting the result of sorting data by multiple columns and returns an array of objects with the following properties:
361397

362-
The method allows getting the result of sorting data by multiple columns.
398+
<table>
399+
<tbody>
400+
<tr>
401+
<td><b>by</b></td>
402+
<td>(<i>string | number</i>) the id of a data field (a column of Grid) to sort by</td>
403+
</tr>
404+
<tr>
405+
<td><b>dir</b></td>
406+
<td>(<i>string</i>) the direction of sorting: "asc" or "desc"</td>
407+
</tr>
408+
<tr>
409+
<td><b>as</b></td>
410+
<td>(<i>function</i>) a custom function of converting values before comparing</td>
411+
</tr>
412+
<tr>
413+
<td><b>rule</b></td>
414+
<td>(<i>function</i>) a custom sorting function</td>
415+
</tr>
416+
<tr>
417+
<td><b>smartSorting</b></td>
418+
<td>(<i>boolean</i>) (if applied) specifies whether a sorting rule should be applied each time after changing the data set</td>
419+
</tr>
420+
</tbody>
421+
</table>
363422

364423
~~~jsx
365424
const state = grid.data.getSortingStates();
366425
// -> [{by: "country", dir: "desc"}, {by: "population", dir: "desc"}]
367426
~~~
368427

369-
**Related sample**: [Grid. Get sorting state](https://snippet.dhtmlx.com/u2vk3ri3)
370428

371429
### Editing data
372430

docs/migration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ description: You can explore how to migrate to newer versions in the documentati
1111

1212
### Grid
1313

14-
The `getSortingState()` method of Grid has been deprecated and replaced with the `getSortingStates()` method of [DataCollection](/data_collection/) and [TreeCollection](/tree_collection/):
14+
The `getSortingState()` method of Grid has been deprecated and replaced with the `getSortingStates()` method of [DataCollection](/data_collection/) and [TreeCollection](/tree_collection/), which allows getting the result of sorting data by multiple columns.
1515

1616
~~~jsx title="Before v9.1"
1717
grid.getSortingState();

0 commit comments

Comments
 (0)