@progress/kendo-data-query 1.7.2 → 1.7.3-develop.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -72,44 +72,50 @@ const rules = (state, encode = true) => key => ({
72
72
  "take": serializePageSize(state)
73
73
  }[key]);
74
74
  /**
75
- * Converts a [DataSourceRequestState]({% slug api_kendo-data-query_datasourcerequeststate %}) into a string
75
+ * Converts a [`DataSourceRequestState`]({% slug api_kendo-data-query_datasourcerequeststate %}) into a string
76
76
  * that is comparable with the `DataSourceRequest` format in UI for ASP.NET MVC.
77
77
  *
78
- * @param {DataSourceRequestState} state - The state that will be serialized.
79
- * @returns {string} - The serialized state.
78
+ * @param {DataSourceRequestState} state The state that will be serialized.
79
+ * @returns {string} The serialized state.
80
+ *
81
+ * The following code snippet demonstrates how to use the `toDataSourceRequestString` method.
80
82
  *
81
83
  * {% platform_content angular %}
82
84
  * ```ts
83
- * import {
84
- * toDataSourceRequestString,
85
- * translateDataSourceResultGroups,
86
- * translateAggregateResults
85
+ * import { HttpClient } from '@angular/common/http';
86
+ * import { Observable } from 'rxjs';
87
+ * import { map } from 'rxjs/operators';
88
+ * import {
89
+ * DataSourceRequestState,
90
+ * toDataSourceRequestString,
91
+ * translateDataSourceResultGroups,
92
+ * translateAggregateResults
87
93
  * } from '@progress/kendo-data-query';
88
94
  *
89
- * export class Service {
90
- * private BASE_URL: string = '...';
91
- *
92
- * constructor(private http: Http) { }
93
- *
94
- * // Omitted for brevity...
95
- *
96
- * private fetch(state: DataSourceRequestState): Observable<DataResult> {
97
- * const queryStr = `${toDataSourceRequestString(state)}`; //serialize the state
98
- * const hasGroups = state.group && state.group.length;
99
- *
100
- * return this.http
101
- * .get(`${this.BASE_URL}?${queryStr}`) //send the state to the server
102
- * .map(response => response.json())
103
- * .map(({Data, Total, AggregateResults}) => // process the response
104
- * (<GridDataResult>{
105
- * //if there are groups convert them to compatible format
106
- * data: hasGroups ? translateDataSourceResultGroups(Data) : Data,
107
- * total: Total,
108
- * // convert the aggregates if such exists
109
- * aggregateResult: translateAggregateResults(AggregateResults)
110
- * })
111
- * );
112
- * }
95
+ * export class ProductService {
96
+ * private BASE_URL = 'https://api.example.com/products';
97
+ *
98
+ * constructor(private http: HttpClient) { }
99
+ *
100
+ * public fetch(state: DataSourceRequestState): Observable<GridDataResult> {
101
+ *
102
+ * // DataSourceRequestState includes:
103
+ * // - State properties: skip, take, sort, filter, group
104
+ * // - Additional property: aggregates
105
+ * const queryString = toDataSourceRequestString(state);
106
+ *
107
+ * const hasGroups = state.group && state.group.length;
108
+ *
109
+ * return this.http
110
+ * .get<ServerResponse>(`${this.BASE_URL}?${queryString}`)
111
+ * .pipe(
112
+ * map(({ Data, Total, AggregateResults }) => ({
113
+ * data: hasGroups ? translateDataSourceResultGroups(Data) : Data,
114
+ * total: Total,
115
+ * aggregateResult: translateAggregateResults(AggregateResults)
116
+ * }))
117
+ * );
118
+ * }
113
119
  * }
114
120
  * ```
115
121
  * {% endplatform_content %}
@@ -123,6 +129,9 @@ const rules = (state, encode = true) => key => ({
123
129
  * return class StatefullGrid extends React.Component {
124
130
  * constructor(props) {
125
131
  * super(props);
132
+ * // DataSourceRequestState includes:
133
+ * // - State properties: skip, take, sort, filter, group
134
+ * // - Additional property: aggregates
126
135
  * this.state = { dataState: { skip: 0, take: 20 } };
127
136
  * }
128
137
  *
@@ -154,6 +163,9 @@ const rules = (state, encode = true) => key => ({
154
163
  * }
155
164
  *
156
165
  * fetchData(dataState) {
166
+ * // DataSourceRequestState includes:
167
+ * // - State properties: skip, take, sort, filter, group
168
+ * // - Additional property: aggregates
157
169
  * const queryStr = `${toDataSourceRequestString(dataState)}`; // Serialize the state
158
170
  * const hasGroups = dataState.group && dataState.group.length;
159
171
  *
@@ -179,11 +191,53 @@ export const toDataSourceRequestString = (state) => (toQueryString(Object.keys(s
179
191
  .map(rules(state))
180
192
  .filter(isPresent)).join('&'));
181
193
  /**
182
- * Converts a [DataSourceRequestState]({% slug api_kendo-data-query_datasourcerequeststate %}) into an object
194
+ * Converts a [`DataSourceRequestState`]({% slug api_kendo-data-query_datasourcerequeststate %}) into an object
183
195
  * that is compatible with the `DataSourceRequest` format in UI for ASP.NET MVC.
184
196
  *
185
- * @param {DataSourceRequestState} state - The state that will be serialized.
186
- * @returns {any} - The serialized state.
197
+ * @param {DataSourceRequestState} state The state that will be serialized.
198
+ * @returns {any} The serialized state.
199
+ *
200
+ * The following code snippet demonstrates how to use the `toDataSourceRequest` method.
201
+ *
202
+ * {% platform_content angular %}
203
+ * ```ts
204
+ * import { HttpClient } from '@angular/common/http';
205
+ * import { Observable } from 'rxjs';
206
+ * import { map } from 'rxjs/operators';
207
+ * import {
208
+ * DataSourceRequestState,
209
+ * toDataSourceRequest,
210
+ * translateDataSourceResultGroups,
211
+ * translateAggregateResults
212
+ * } from '@progress/kendo-data-query';
213
+ *
214
+ * export class ProductService {
215
+ * private BASE_URL = 'https://api.example.com/products';
216
+ *
217
+ * constructor(private http: HttpClient) { }
218
+ *
219
+ * public fetch(state: DataSourceRequestState): Observable<GridDataResult> {
220
+ *
221
+ * // DataSourceRequestState includes:
222
+ * // - State properties: skip, take, sort, filter, group
223
+ * // - Additional property: aggregates
224
+ * const dataSourceRequest = toDataSourceRequest(state);
225
+ *
226
+ * const hasGroups = state.group && state.group.length;
227
+ *
228
+ * return this.http
229
+ * .post<ServerResponse>(this.BASE_URL, dataSourceRequest)
230
+ * .pipe(
231
+ * map(({ Data, Total, AggregateResults }) => ({
232
+ * data: hasGroups ? translateDataSourceResultGroups(Data) : Data,
233
+ * total: Total,
234
+ * aggregateResult: translateAggregateResults(AggregateResults)
235
+ * }))
236
+ * );
237
+ * }
238
+ * }
239
+ * ```
240
+ * {% endplatform_content %}
187
241
  */
188
242
  export const toDataSourceRequest = (state) => (toObject(Object.keys(state)
189
243
  .map(rules(state, false))
@@ -5,6 +5,7 @@ var transducers_1 = require("../transducers");
5
5
  var utils_1 = require("../utils");
6
6
  var aggregate_operators_1 = require("./aggregate.operators");
7
7
  var filter_expression_factory_1 = require("../filtering/filter-expression.factory");
8
+ var sort_array_operator_1 = require("../sorting/sort-array.operator");
8
9
  /**
9
10
  * @hidden
10
11
  */
@@ -73,6 +74,15 @@ var groupBy = function (data, descriptors, transformers, originalData) {
73
74
  };
74
75
  });
75
76
  });
77
+ // Sort the result according to the descriptor's dir and compare options
78
+ if ((0, utils_1.isPresent)(descriptor.dir) || (0, utils_1.isPresent)(descriptor.compare)) {
79
+ var comparer = (0, sort_array_operator_1.composeSortDescriptors)([{
80
+ field: 'value',
81
+ dir: descriptor.dir,
82
+ compare: descriptor.compare
83
+ }]);
84
+ result.sort(comparer);
85
+ }
76
86
  return result;
77
87
  };
78
88
  exports.groupBy = groupBy;
@@ -27,13 +27,13 @@ export type ServerGroupResult = {
27
27
  };
28
28
  /**
29
29
  * Converts the grouped result, which is returned into the `Data` field of the UI for ASP.NET MVC `ToDataSourceResult` method, to a comparable format.
30
- * @param data - The value of the `Data` field of the response.
31
- * @returns {GroupResult[]} - The converted result.
30
+ * @param data The value of the `Data` field of the response.
31
+ * @returns {GroupResult[]} The converted result.
32
32
  */
33
33
  export declare const translateDataSourceResultGroups: (data: any[]) => GroupResult[];
34
34
  /**
35
35
  * Converts the `AggregateResults` field content, which is returned by the UI for ASP.NET MVC `ToDataSourceResult` method, to a comparable format.
36
- * @param data - The value of the `AggregateResults` field of the response.
37
- * @returns {AggregateResult} - The converted result.
36
+ * @param data The value of the `AggregateResults` field of the response.
37
+ * @returns {AggregateResult} The converted result.
38
38
  */
39
39
  export declare const translateAggregateResults: (data: any[]) => AggregateResult;
@@ -42,15 +42,15 @@ var translateGroup = (0, funcs_1.compose)(function (_a) {
42
42
  // tslint:disable:max-line-length
43
43
  /**
44
44
  * Converts the grouped result, which is returned into the `Data` field of the UI for ASP.NET MVC `ToDataSourceResult` method, to a comparable format.
45
- * @param data - The value of the `Data` field of the response.
46
- * @returns {GroupResult[]} - The converted result.
45
+ * @param data The value of the `Data` field of the response.
46
+ * @returns {GroupResult[]} The converted result.
47
47
  */
48
48
  var translateDataSourceResultGroups = function (data) { return data.map(translateGroup); };
49
49
  exports.translateDataSourceResultGroups = translateDataSourceResultGroups;
50
50
  /**
51
51
  * Converts the `AggregateResults` field content, which is returned by the UI for ASP.NET MVC `ToDataSourceResult` method, to a comparable format.
52
- * @param data - The value of the `AggregateResults` field of the response.
53
- * @returns {AggregateResult} - The converted result.
52
+ * @param data The value of the `AggregateResults` field of the response.
53
+ * @returns {AggregateResult} The converted result.
54
54
  */
55
55
  // tslint:enable:max-line-length
56
56
  var translateAggregateResults = function (data) { return ((data || []).reduce(function (acc, x) { return set(member(x), acc, set(aggregateMethodName(x).toLowerCase(), acc[member(x)] || {}, value(x))); }, {})); };
@@ -1,11 +1,31 @@
1
1
  import { State } from '../state';
2
2
  import { AggregateDescriptor } from '../grouping/aggregate.operators';
3
3
  /**
4
- * Represents the operation descriptors that will be sent
5
- * ([see example]({% slug api_kendo-data-query_todatasourcerequeststring %})).
4
+ * Represents the state required by the [`toDataSourceRequest`]({% slug api_kendo-data-query_todatasourcerequest %})
5
+ * and [`toDataSourceRequestString`]({% slug api_kendo-data-query_todatasourcerequeststring %}) methods.
6
6
  *
7
- * Extends [State]({% slug api_kendo-data-query_state %}) by adding the `aggregates` descriptors&mdash;
8
- * an array of [AggregateDescriptor]({% slug api_kendo-data-query_aggregatedescriptor %}).
7
+ * The `DataSourceRequestState` is an extension of the [`State`]({% slug api_kendo-data-query_state %}) type
8
+ * with an additional `aggregates` field&mdash;an array of [`AggregateDescriptor`]({% slug api_kendo-data-query_aggregatedescriptor %}).
9
+ *
10
+ * The aggregates field is required for serialization of aggregate descriptors in the request and does not replace the `aggregate` field
11
+ * of the [`GroupDescriptor`]({% slug api_kendo-data-query_groupdescriptor %}) used by the `group` field.
12
+ *
13
+ * ```ts
14
+ * import { DataSourceRequestState } from '@progress/kendo-data-query';
15
+ *
16
+ * const state: DataSourceRequestState = {
17
+ * skip: 0,
18
+ * take: 10,
19
+ * sort: [{ field: 'ProductName', dir: 'asc' }],
20
+ * group: [
21
+ * {
22
+ * field: 'Category',
23
+ * aggregates: [{ field: 'UnitPrice', aggregate: 'sum' }] // GroupDescriptor aggregates
24
+ * }
25
+ * ],
26
+ * aggregates: [{ field: 'UnitPrice', aggregate: 'sum' }] // DataSourceRequestState aggregates
27
+ * };
28
+ * ```
9
29
  */
10
30
  export type DataSourceRequestState = State & {
11
31
  /**
@@ -15,44 +35,50 @@ export type DataSourceRequestState = State & {
15
35
  aggregates?: Array<AggregateDescriptor>;
16
36
  };
17
37
  /**
18
- * Converts a [DataSourceRequestState]({% slug api_kendo-data-query_datasourcerequeststate %}) into a string
38
+ * Converts a [`DataSourceRequestState`]({% slug api_kendo-data-query_datasourcerequeststate %}) into a string
19
39
  * that is comparable with the `DataSourceRequest` format in UI for ASP.NET MVC.
20
40
  *
21
- * @param {DataSourceRequestState} state - The state that will be serialized.
22
- * @returns {string} - The serialized state.
41
+ * @param {DataSourceRequestState} state The state that will be serialized.
42
+ * @returns {string} The serialized state.
43
+ *
44
+ * The following code snippet demonstrates how to use the `toDataSourceRequestString` method.
23
45
  *
24
46
  * {% platform_content angular %}
25
47
  * ```ts
26
- * import {
27
- * toDataSourceRequestString,
28
- * translateDataSourceResultGroups,
29
- * translateAggregateResults
48
+ * import { HttpClient } from '@angular/common/http';
49
+ * import { Observable } from 'rxjs';
50
+ * import { map } from 'rxjs/operators';
51
+ * import {
52
+ * DataSourceRequestState,
53
+ * toDataSourceRequestString,
54
+ * translateDataSourceResultGroups,
55
+ * translateAggregateResults
30
56
  * } from '@progress/kendo-data-query';
31
57
  *
32
- * export class Service {
33
- * private BASE_URL: string = '...';
34
- *
35
- * constructor(private http: Http) { }
36
- *
37
- * // Omitted for brevity...
38
- *
39
- * private fetch(state: DataSourceRequestState): Observable<DataResult> {
40
- * const queryStr = `${toDataSourceRequestString(state)}`; //serialize the state
41
- * const hasGroups = state.group && state.group.length;
42
- *
43
- * return this.http
44
- * .get(`${this.BASE_URL}?${queryStr}`) //send the state to the server
45
- * .map(response => response.json())
46
- * .map(({Data, Total, AggregateResults}) => // process the response
47
- * (<GridDataResult>{
48
- * //if there are groups convert them to compatible format
49
- * data: hasGroups ? translateDataSourceResultGroups(Data) : Data,
50
- * total: Total,
51
- * // convert the aggregates if such exists
52
- * aggregateResult: translateAggregateResults(AggregateResults)
53
- * })
54
- * );
55
- * }
58
+ * export class ProductService {
59
+ * private BASE_URL = 'https://api.example.com/products';
60
+ *
61
+ * constructor(private http: HttpClient) { }
62
+ *
63
+ * public fetch(state: DataSourceRequestState): Observable<GridDataResult> {
64
+ *
65
+ * // DataSourceRequestState includes:
66
+ * // - State properties: skip, take, sort, filter, group
67
+ * // - Additional property: aggregates
68
+ * const queryString = toDataSourceRequestString(state);
69
+ *
70
+ * const hasGroups = state.group && state.group.length;
71
+ *
72
+ * return this.http
73
+ * .get<ServerResponse>(`${this.BASE_URL}?${queryString}`)
74
+ * .pipe(
75
+ * map(({ Data, Total, AggregateResults }) => ({
76
+ * data: hasGroups ? translateDataSourceResultGroups(Data) : Data,
77
+ * total: Total,
78
+ * aggregateResult: translateAggregateResults(AggregateResults)
79
+ * }))
80
+ * );
81
+ * }
56
82
  * }
57
83
  * ```
58
84
  * {% endplatform_content %}
@@ -66,6 +92,9 @@ export type DataSourceRequestState = State & {
66
92
  * return class StatefullGrid extends React.Component {
67
93
  * constructor(props) {
68
94
  * super(props);
95
+ * // DataSourceRequestState includes:
96
+ * // - State properties: skip, take, sort, filter, group
97
+ * // - Additional property: aggregates
69
98
  * this.state = { dataState: { skip: 0, take: 20 } };
70
99
  * }
71
100
  *
@@ -97,6 +126,9 @@ export type DataSourceRequestState = State & {
97
126
  * }
98
127
  *
99
128
  * fetchData(dataState) {
129
+ * // DataSourceRequestState includes:
130
+ * // - State properties: skip, take, sort, filter, group
131
+ * // - Additional property: aggregates
100
132
  * const queryStr = `${toDataSourceRequestString(dataState)}`; // Serialize the state
101
133
  * const hasGroups = dataState.group && dataState.group.length;
102
134
  *
@@ -120,10 +152,52 @@ export type DataSourceRequestState = State & {
120
152
  */
121
153
  export declare const toDataSourceRequestString: (state: DataSourceRequestState) => string;
122
154
  /**
123
- * Converts a [DataSourceRequestState]({% slug api_kendo-data-query_datasourcerequeststate %}) into an object
155
+ * Converts a [`DataSourceRequestState`]({% slug api_kendo-data-query_datasourcerequeststate %}) into an object
124
156
  * that is compatible with the `DataSourceRequest` format in UI for ASP.NET MVC.
125
157
  *
126
- * @param {DataSourceRequestState} state - The state that will be serialized.
127
- * @returns {any} - The serialized state.
158
+ * @param {DataSourceRequestState} state The state that will be serialized.
159
+ * @returns {any} The serialized state.
160
+ *
161
+ * The following code snippet demonstrates how to use the `toDataSourceRequest` method.
162
+ *
163
+ * {% platform_content angular %}
164
+ * ```ts
165
+ * import { HttpClient } from '@angular/common/http';
166
+ * import { Observable } from 'rxjs';
167
+ * import { map } from 'rxjs/operators';
168
+ * import {
169
+ * DataSourceRequestState,
170
+ * toDataSourceRequest,
171
+ * translateDataSourceResultGroups,
172
+ * translateAggregateResults
173
+ * } from '@progress/kendo-data-query';
174
+ *
175
+ * export class ProductService {
176
+ * private BASE_URL = 'https://api.example.com/products';
177
+ *
178
+ * constructor(private http: HttpClient) { }
179
+ *
180
+ * public fetch(state: DataSourceRequestState): Observable<GridDataResult> {
181
+ *
182
+ * // DataSourceRequestState includes:
183
+ * // - State properties: skip, take, sort, filter, group
184
+ * // - Additional property: aggregates
185
+ * const dataSourceRequest = toDataSourceRequest(state);
186
+ *
187
+ * const hasGroups = state.group && state.group.length;
188
+ *
189
+ * return this.http
190
+ * .post<ServerResponse>(this.BASE_URL, dataSourceRequest)
191
+ * .pipe(
192
+ * map(({ Data, Total, AggregateResults }) => ({
193
+ * data: hasGroups ? translateDataSourceResultGroups(Data) : Data,
194
+ * total: Total,
195
+ * aggregateResult: translateAggregateResults(AggregateResults)
196
+ * }))
197
+ * );
198
+ * }
199
+ * }
200
+ * ```
201
+ * {% endplatform_content %}
128
202
  */
129
203
  export declare const toDataSourceRequest: (state: DataSourceRequestState) => any;
@@ -116,44 +116,50 @@ var rules = function (state, encode) {
116
116
  }[key]); };
117
117
  };
118
118
  /**
119
- * Converts a [DataSourceRequestState]({% slug api_kendo-data-query_datasourcerequeststate %}) into a string
119
+ * Converts a [`DataSourceRequestState`]({% slug api_kendo-data-query_datasourcerequeststate %}) into a string
120
120
  * that is comparable with the `DataSourceRequest` format in UI for ASP.NET MVC.
121
121
  *
122
- * @param {DataSourceRequestState} state - The state that will be serialized.
123
- * @returns {string} - The serialized state.
122
+ * @param {DataSourceRequestState} state The state that will be serialized.
123
+ * @returns {string} The serialized state.
124
+ *
125
+ * The following code snippet demonstrates how to use the `toDataSourceRequestString` method.
124
126
  *
125
127
  * {% platform_content angular %}
126
128
  * ```ts
127
- * import {
128
- * toDataSourceRequestString,
129
- * translateDataSourceResultGroups,
130
- * translateAggregateResults
129
+ * import { HttpClient } from '@angular/common/http';
130
+ * import { Observable } from 'rxjs';
131
+ * import { map } from 'rxjs/operators';
132
+ * import {
133
+ * DataSourceRequestState,
134
+ * toDataSourceRequestString,
135
+ * translateDataSourceResultGroups,
136
+ * translateAggregateResults
131
137
  * } from '@progress/kendo-data-query';
132
138
  *
133
- * export class Service {
134
- * private BASE_URL: string = '...';
135
- *
136
- * constructor(private http: Http) { }
137
- *
138
- * // Omitted for brevity...
139
- *
140
- * private fetch(state: DataSourceRequestState): Observable<DataResult> {
141
- * const queryStr = `${toDataSourceRequestString(state)}`; //serialize the state
142
- * const hasGroups = state.group && state.group.length;
143
- *
144
- * return this.http
145
- * .get(`${this.BASE_URL}?${queryStr}`) //send the state to the server
146
- * .map(response => response.json())
147
- * .map(({Data, Total, AggregateResults}) => // process the response
148
- * (<GridDataResult>{
149
- * //if there are groups convert them to compatible format
150
- * data: hasGroups ? translateDataSourceResultGroups(Data) : Data,
151
- * total: Total,
152
- * // convert the aggregates if such exists
153
- * aggregateResult: translateAggregateResults(AggregateResults)
154
- * })
155
- * );
156
- * }
139
+ * export class ProductService {
140
+ * private BASE_URL = 'https://api.example.com/products';
141
+ *
142
+ * constructor(private http: HttpClient) { }
143
+ *
144
+ * public fetch(state: DataSourceRequestState): Observable<GridDataResult> {
145
+ *
146
+ * // DataSourceRequestState includes:
147
+ * // - State properties: skip, take, sort, filter, group
148
+ * // - Additional property: aggregates
149
+ * const queryString = toDataSourceRequestString(state);
150
+ *
151
+ * const hasGroups = state.group && state.group.length;
152
+ *
153
+ * return this.http
154
+ * .get<ServerResponse>(`${this.BASE_URL}?${queryString}`)
155
+ * .pipe(
156
+ * map(({ Data, Total, AggregateResults }) => ({
157
+ * data: hasGroups ? translateDataSourceResultGroups(Data) : Data,
158
+ * total: Total,
159
+ * aggregateResult: translateAggregateResults(AggregateResults)
160
+ * }))
161
+ * );
162
+ * }
157
163
  * }
158
164
  * ```
159
165
  * {% endplatform_content %}
@@ -167,6 +173,9 @@ var rules = function (state, encode) {
167
173
  * return class StatefullGrid extends React.Component {
168
174
  * constructor(props) {
169
175
  * super(props);
176
+ * // DataSourceRequestState includes:
177
+ * // - State properties: skip, take, sort, filter, group
178
+ * // - Additional property: aggregates
170
179
  * this.state = { dataState: { skip: 0, take: 20 } };
171
180
  * }
172
181
  *
@@ -198,6 +207,9 @@ var rules = function (state, encode) {
198
207
  * }
199
208
  *
200
209
  * fetchData(dataState) {
210
+ * // DataSourceRequestState includes:
211
+ * // - State properties: skip, take, sort, filter, group
212
+ * // - Additional property: aggregates
201
213
  * const queryStr = `${toDataSourceRequestString(dataState)}`; // Serialize the state
202
214
  * const hasGroups = dataState.group && dataState.group.length;
203
215
  *
@@ -224,11 +236,53 @@ var toDataSourceRequestString = function (state) { return (toQueryString(Object.
224
236
  .filter(utils_1.isPresent)).join('&')); };
225
237
  exports.toDataSourceRequestString = toDataSourceRequestString;
226
238
  /**
227
- * Converts a [DataSourceRequestState]({% slug api_kendo-data-query_datasourcerequeststate %}) into an object
239
+ * Converts a [`DataSourceRequestState`]({% slug api_kendo-data-query_datasourcerequeststate %}) into an object
228
240
  * that is compatible with the `DataSourceRequest` format in UI for ASP.NET MVC.
229
241
  *
230
- * @param {DataSourceRequestState} state - The state that will be serialized.
231
- * @returns {any} - The serialized state.
242
+ * @param {DataSourceRequestState} state The state that will be serialized.
243
+ * @returns {any} The serialized state.
244
+ *
245
+ * The following code snippet demonstrates how to use the `toDataSourceRequest` method.
246
+ *
247
+ * {% platform_content angular %}
248
+ * ```ts
249
+ * import { HttpClient } from '@angular/common/http';
250
+ * import { Observable } from 'rxjs';
251
+ * import { map } from 'rxjs/operators';
252
+ * import {
253
+ * DataSourceRequestState,
254
+ * toDataSourceRequest,
255
+ * translateDataSourceResultGroups,
256
+ * translateAggregateResults
257
+ * } from '@progress/kendo-data-query';
258
+ *
259
+ * export class ProductService {
260
+ * private BASE_URL = 'https://api.example.com/products';
261
+ *
262
+ * constructor(private http: HttpClient) { }
263
+ *
264
+ * public fetch(state: DataSourceRequestState): Observable<GridDataResult> {
265
+ *
266
+ * // DataSourceRequestState includes:
267
+ * // - State properties: skip, take, sort, filter, group
268
+ * // - Additional property: aggregates
269
+ * const dataSourceRequest = toDataSourceRequest(state);
270
+ *
271
+ * const hasGroups = state.group && state.group.length;
272
+ *
273
+ * return this.http
274
+ * .post<ServerResponse>(this.BASE_URL, dataSourceRequest)
275
+ * .pipe(
276
+ * map(({ Data, Total, AggregateResults }) => ({
277
+ * data: hasGroups ? translateDataSourceResultGroups(Data) : Data,
278
+ * total: Total,
279
+ * aggregateResult: translateAggregateResults(AggregateResults)
280
+ * }))
281
+ * );
282
+ * }
283
+ * }
284
+ * ```
285
+ * {% endplatform_content %}
232
286
  */
233
287
  var toDataSourceRequest = function (state) { return (toObject(Object.keys(state)
234
288
  .map(rules(state, false))