DevExtreme jQuery - Query Methods
aggregate(seed, step, finalize)
A Promise that is resolved after the operation is completed. It is a native Promise or a jQuery.Promise when you use jQuery.
- var step = function (total, itemData) {
- // "total" is an accumulator value that should be changed on each iteration
- // "itemData" is the item to which the function is being applied
- return total + itemData;
- };
- var finalize = function (total) {
- // "total" is the resulting accumulator value
- return total / 1000;
- };
- DevExpress.data.query([10, 20, 30, 40, 50])
- .aggregate(0, step, finalize)
- .done(function (result) {
- console.log(result); // outputs 0.15
- });
aggregate(step)
A Promise that is resolved after the operation is completed. It is a native Promise or a jQuery.Promise when you use jQuery.
This is a shortcut for the aggregate(seed, step, finalize) method. It omits the seed and finalize parameters: instead of the seed value, the accumulator value is initialized with the first item's value; the finalize parameter's omission means that the calculation result is the accumulator value after the last step function's execution.
- var step = function (total, itemData) {
- // "total" is an accumulator value that should be changed on each iteration
- // "itemData" is the item to which the function is being applied
- return total + itemData;
- };
- DevExpress.data.query([10, 20, 30, 40, 50])
- .aggregate(step)
- .done(function (result) {
- console.log(result); // outputs 150
- });
avg()
A Promise that is resolved after the operation is completed. It is a native Promise or a jQuery.Promise when you use jQuery.
First, call the select(getter) method to select the object field that provides numeric values if the Query is associated with an array of objects, or use the avg(getter) method instead of avg().
- var dataObjects = [ ... ];
- DevExpress.data.query(dataObjects)
- .select("price")
- .avg()
- .done(function (result) {
- // "result" contains the calculated value
- });
avg(getter)
Calculates the average of all values found using a getter.
A Promise that is resolved after the operation is completed. It is a native Promise or a jQuery.Promise when you use jQuery.
- var dataObjects = [ ... ];
- DevExpress.data.query(dataObjects)
- .avg("price")
- .done(function (result) {
- // "result" contains the calculated value
- });
If the Query is associated with a numeric array, use the avg() method instead.
count()
A Promise that is resolved after the operation is completed. It is a native Promise or a jQuery.Promise when you use jQuery.
enumerate()
Executes the Query. This is an asynchronous alternative to the toArray() method.
A Promise that is resolved after the operation is completed. It is a native Promise or a jQuery.Promise when you use jQuery.
filter(predicate)
- var filteredData = DevExpress.data.query([10, 20, 40, 50, 30])
- .filter(function (dataItem) {
- return dataItem < 25;
- })
- .toArray();
- console.log(filteredData); // outputs [10, 20]
See Also
groupBy(getter)
Groups data items by the specified getter.
- var dataObjects = [
- { name: "Amelia", birthYear: 1991, gender: "female" },
- { name: "Benjamin", birthYear: 1983, gender: "male" },
- { name: "Daniela", birthYear: 1987, gender: "female" },
- { name: "Lee", birthYear: 1981, gender: "male" }
- ];
- var groupedData = DevExpress.data.query(dataObjects)
- .groupBy("gender")
- .toArray();
- console.log(groupedData);
- /* outputs
- [{
- key: "female",
- items: [
- { name: "Amelia", birthYear: 1991, gender: "female" },
- { name: "Daniela", birthYear: 1987, gender: "female" }
- ]
- }, {
- key: "male",
- items: [
- { name: "Benjamin", birthYear: 1983, gender: "male" },
- { name: "Lee", birthYear: 1981, gender: "male" }
- ]
- }] */
See Also
max()
A Promise that is resolved after the operation is completed. It is a native Promise or a jQuery.Promise when you use jQuery.
First, call the select(getter) method to select the object field that provides numeric values if the Query is associated with an array of objects, or use the max(getter) method instead of max().
- var dataObjects = [ ... ];
- DevExpress.data.query(dataObjects)
- .select("price")
- .max()
- .done(function (result) {
- // "result" contains the calculated value
- });
max(getter)
Calculates the maximum of all values found using a getter.
A Promise that is resolved after the operation is completed. It is a native Promise or a jQuery.Promise when you use jQuery.
- var dataObjects = [ ... ];
- DevExpress.data.query(dataObjects)
- .max("price")
- .done(function (result) {
- // "result" contains the calculated value
- });
If the Query is associated with a numeric array, use the max() method instead.
min()
A Promise that is resolved after the operation is completed. It is a native Promise or a jQuery.Promise when you use jQuery.
First, call the select(getter) method to select the object field that provides numeric values if the Query is associated with an array of objects, or use the min(getter) method instead of min().
- var dataObjects = [ ... ];
- DevExpress.data.query(dataObjects)
- .select("price")
- .min()
- .done(function (result) {
- // "result" contains the calculated value
- });
min(getter)
Calculates the minumum of all values found using a getter.
A Promise that is resolved after the operation is completed. It is a native Promise or a jQuery.Promise when you use jQuery.
- var dataObjects = [ ... ];
- DevExpress.data.query(dataObjects)
- .min("price")
- .done(function (result) {
- // "result" contains the calculated value
- });
If the Query is associated with a numeric array, use the min() method instead.
select(getter)
- var dataObjects = [
- { name: "Amelia", birthYear: 1991, gender: "female" },
- { name: "Benjamin", birthYear: 1983, gender: "male" },
- { name: "Daniela", birthYear: 1987, gender: "female" },
- { name: "Lee", birthYear: 1981, gender: "male" }
- ];
- var selectedData = DevExpress.data.query(dataObjects)
- .select("birthYear", "name")
- .toArray();
- console.log(selectedData);
- /* outputs
- [
- { birthYear: 1991, name: "Amelia" },
- { birthYear: 1983, name: "Benjamin" },
- { birthYear: 1987, name: "Daniela" },
- { birthYear: 1981, name: "Lee" }
- ] */
slice(skip, take)
- var dataObjects = [
- { name: "Amelia", birthYear: 1991, gender: "female" },
- { name: "Benjamin", birthYear: 1983, gender: "male" },
- { name: "Daniela", birthYear: 1987, gender: "female" },
- { name: "Lee", birthYear: 1981, gender: "male" }
- ];
- var subset = DevExpress.data.query(dataObjects)
- .slice(1, 2)
- .toArray();
- console.log(subset);
- /* outputs
- [
- { name: "Benjamin", birthYear: 1983, gender: "male" },
- { name: "Daniela", birthYear: 1987, gender: "female" }
- ] */
sortBy(getter)
Sorts data items by the specified getter in ascending order.
- var dataObjects = [
- { name: "Amelia", birthYear: 1991, gender: "female" },
- { name: "Benjamin", birthYear: 1983, gender: "male" },
- { name: "Daniela", birthYear: 1987, gender: "female" },
- { name: "Lee", birthYear: 1981, gender: "male" }
- ];
- var sortedData = DevExpress.data.query(dataObjects)
- .sortBy("birthYear")
- .toArray();
- console.log(sortedData);
- /* outputs
- [
- { name: "Lee", birthYear: 1981, gender: "male" },
- { name: "Benjamin", birthYear: 1983, gender: "male" },
- { name: "Daniela", birthYear: 1987, gender: "female" },
- { name: "Amelia", birthYear: 1991, gender: "female" }
- ] */
To sort data items by one more getter, call the thenBy(getter) or thenBy(getter, desc) method after sortBy.
See Also
sortBy(getter, desc)
Sorts data items by the specified getter in the specified sorting order.
- var dataObjects = [
- { name: "Amelia", birthYear: 1991, gender: "female" },
- { name: "Benjamin", birthYear: 1983, gender: "male" },
- { name: "Daniela", birthYear: 1987, gender: "female" },
- { name: "Lee", birthYear: 1981, gender: "male" }
- ];
- var sortedData = DevExpress.data.query(dataObjects)
- .sortBy("birthYear", true)
- .toArray();
- console.log(sortedData);
- /* outputs
- [
- { name: "Amelia", birthYear: 1991, gender: "female" },
- { name: "Daniela", birthYear: 1987, gender: "female" },
- { name: "Benjamin", birthYear: 1983, gender: "male" },
- { name: "Lee", birthYear: 1981, gender: "male" }
- ] */
Call the thenBy(getter) or thenBy(getter, desc) method after sortBy to sort data items by one more getter.
See Also
sum()
A Promise that is resolved after the operation is completed. It is a native Promise or a jQuery.Promise when you use jQuery.
First, call the select(getter) method to select the object field that provides numeric values if the Query is associated with an array of objects, or use the sum(getter) method instead of sum().
- var dataObjects = [ ... ];
- DevExpress.data.query(dataObjects)
- .select("price")
- .sum()
- .done(function (result) {
- // "result" contains the calculated value
- });
sum(getter)
Calculates the sum of all values found using a getter.
A Promise that is resolved after the operation is completed. It is a native Promise or a jQuery.Promise when you use jQuery.
- var dataObjects = [ ... ];
- DevExpress.data.query(dataObjects)
- .sum("price")
- .done(function (result) {
- // "result" contains the calculated value
- });
If the Query is associated with a numeric array, use the sum() method instead.
thenBy(getter)
Sorts data items by one more getter in ascending order.
This method can only follow the sortBy(getter), sortBy(getter, desc), thenBy(getter, desc), or another thenBy(getter) method call.
- var dataObjects = [
- { name: "Amelia", birthYear: 1991, gender: "female" },
- { name: "Benjamin", birthYear: 1983, gender: "male" },
- { name: "Daniela", birthYear: 1987, gender: "female" },
- { name: "Lee", birthYear: 1981, gender: "male" }
- ];
- var sortedData = DevExpress.data.query(dataObjects)
- .sortBy("gender")
- .thenBy("birthYear")
- .toArray();
- console.log(sortedData);
- /* outputs
- [
- { name: "Daniela", birthYear: 1987, gender: "female" },
- { name: "Amelia", birthYear: 1991, gender: "female" },
- { name: "Lee", birthYear: 1981, gender: "male" },
- { name: "Benjamin", birthYear: 1983, gender: "male" }
- ] */
See Also
thenBy(getter, desc)
Sorts data items by one more getter in the specified sorting order.
This method can only follow the sortBy(getter), sortBy(getter, desc), thenBy(getter), or another thenBy(getter, desc) method call.
- var dataObjects = [
- { name: "Amelia", birthYear: 1991, gender: "female" },
- { name: "Benjamin", birthYear: 1983, gender: "male" },
- { name: "Daniela", birthYear: 1987, gender: "female" },
- { name: "Lee", birthYear: 1981, gender: "male" }
- ];
- var sortedData = DevExpress.data.query(dataObjects)
- .sortBy("gender")
- .thenBy("birthYear", true)
- .toArray();
- console.log(sortedData);
- /* outputs
- [
- { name: "Amelia", birthYear: 1991, gender: "female" },
- { name: "Daniela", birthYear: 1987, gender: "female" },
- { name: "Benjamin", birthYear: 1983, gender: "male" },
- { name: "Lee", birthYear: 1981, gender: "male" }
- ] */
See Also
toArray()
Gets data items associated with the Query. This is a synchronous alternative to the enumerate() method.
Array<any>
If you have technical questions, please create a support ticket in the DevExpress Support Center.