Api query in EJ2 TypeScript Data control

2 Dec 20238 minutes to read

Query class is used to build query which is used by the DataManager to communicate with datasource.

Methods

addParams

Adds additional parameter which will be sent along with the request which will be generated while DataManager execute.

Parameter Type Description
key string Defines the key of additional parameter.
value Function | string Defines the value for the key.

Returns Query

aggregate

Aggregate the data with given type and field name.

Parameter Type Description
type string Defines the aggregate type.
field string Defines the column field to aggregate.

Returns Query

clone

Creates deep copy of the Query object.

Returns Query

execute

Executes query with the given DataManager.

Parameter Type Description
dataManager (optional) DataManager Defines the DataManager.
done (optional) Function Defines the success callback.
fail (optional) Function Defines the failure callback.
always (optional) Function Defines the callback which will be invoked on either success or failure.

<pre>
let dataManager: DataManager = new DataManager([{ ID: ‘10’ }, { ID: ‘2’ }, { ID: ‘1’ }, { ID: ‘20’ }]);
let query: Query = new Query();
query.sortBy(‘ID’, (x: string, y: string): number => { return parseInt(x, 10) - parseInt(y, 10) });
let promise: Promise< Object > = query.execute(dataManager);
promise.then((e: { result: Object }) => { });
</pre>

Returns Promise

executeLocal

Executes query with the local datasource.

Parameter Type Description
dataManager (optional) DataManager Defines the DataManager.

Returns Object[]

expand

Expands the related table.

Parameter Type Description
tables string | Object[]

Returns Query

foreignKey

Sets the foreign key which is used to get data from the related table.

Parameter Type Description
key string Defines the foreign key.

Returns Query

from

Specifies the name of table to retrieve data in query execution.

Parameter Type Description
tableName string Defines the table name.

Returns Query

group

Groups data with the given field name.

Returns Query

hierarchy

Gets the records in hierarchical relationship from two tables. It requires the foreign key to relate two tables.

Parameter Type Description
query Query Defines the query to relate two tables.
selectorFn Function Defines the custom function to select records.

Returns Query

page

Gets data based on the given page index and size.

Parameter Type Description
pageIndex number Defines the current page index.
pageSize number Defines the no of records per page.

Returns Query

range

Gets data based on the given start and end index.

Parameter Type Description
start number Defines the start index of the datasource.
end number Defines the end index of the datasource.

Returns Query

requiresCount

It is used to get total number of records in the DataManager execution result.

Returns Query

Search data with given search criteria.

Returns Query

select

Selects specified columns from the data source.

Parameter Type Description
fieldNames string | string[] Defines the collection of column fields.

Returns Query

setKey

Sets the primary key.

Parameter Type Description
field string Defines the column field.

Returns Query

skip

Skips data with given number of records count from the top of the data source.

Parameter Type Description
nos number Defines the no of records skip in the datasource.

Returns Query

sortBy

Sort the data with given sort criteria. By default, sort direction is ascending.

Returns Query

sortByDesc

Sorts data in descending order.

Parameter Type Description
fieldName string Defines the column field.

Returns Query

take

Gets data from the top of the data source based on given number of records count.

Parameter Type Description
nos number Defines the no of records to retrieve from datasource.

Returns Query

using

Sets default DataManager to execute query.

Parameter Type Description
dataManager DataManager Defines the DataManager.

Returns Query

where

Filter data with given filter criteria.

Returns Query