New to Kendo UI for Angular? Start a free 30-day trial
toDataSourceRequestString
Converts a DataSourceRequestState into a string
that is comparable with the DataSourceRequest
format in UI for ASP.NET MVC.
ts
import {
toDataSourceRequestString,
translateDataSourceResultGroups,
translateAggregateResults
} from '@progress/kendo-data-query';
export class Service {
private BASE_URL: string = '...';
constructor(private http: Http) { }
// Omitted for brevity...
private fetch(state: DataSourceRequestState): Observable<DataResult> {
const queryStr = `${toDataSourceRequestString(state)}`; //serialize the state
const hasGroups = state.group && state.group.length;
return this.http
.get(`${this.BASE_URL}?${queryStr}`) //send the state to the server
.map(response => response.json())
.map(({Data, Total, AggregateResults}) => // process the response
(<GridDataResult>{
//if there are groups convert them to compatible format
data: hasGroups ? translateDataSourceResultGroups(Data) : Data,
total: Total,
// convert the aggregates if such exists
aggregateResult: translateAggregateResults(AggregateResults)
})
);
}
}
Parameters
state DataSourceRequestState
The state that will be serialized.
Returns
string - The serialized state.