Search...
ascending( )
Adds a sort to an aggregation, sorting by the items or groups by the specified properties in ascending order.
Description
The ascending()
function refines a WixDataAggregate
to sort the resulting
items or groups in ascending order. If you specify more than one property,
ascending()
sorts the results in ascending order by each property in the
order they are listed.
You can sort the following types:
- Number: Sorts numerically.
- Date: Sorts by date and time.
- String: Sorts lexicographically, so
"abc"
comes after"XYZ"
. - Reference: Compares by the ID of the referenced item as a String.
If a property contains a number as a String, that value will be sorted alphabetically and not numerically. Items that do not have a value for the specified sort property are ranked lowest.
Note: Aggregations can only be used on collections you have created. They cannot be used on Wix App Collections.
Syntax
function ascending(propertyName: ...string): WixDataAggregate
ascending Parameters
NAME
TYPE
DESCRIPTION
propertyName
string
The properties used in the sort.
Was this helpful?
Add an ascending sort to an aggregation
Copy Code
1let newAggregate = aggregate.ascending("state", "city");
Create an aggregation, add an ascending sort, and run it
Copy Code
1import wixData from 'wix-data';23// ...45wixData.aggregate("PopulationData")6 .group("state", "year")7 .avg("population")8 .ascending("populationAvg")9 .run()10 .then((results) => {11 let items = results.items; // see below12 let numItems = results.length; // 613 let hasNext = results.hasNext(); // false14 })15 .catch((error) => {16 let errorMsg = error.message;17 let code = error.code;18 });1920/* Given the sample data above, items is:21 * [22 * {23 * "_id": {"state": "NY", "year": 2010},24 * "populationAvg": 4226500,25 * "state": "NY",26 * "year": 201027 * }, {28 * "_id": {"state": "NY", "year": 2000},29 * "populationAvg": 4153500,30 * "state": "NY",31 * "year": 200032 * }, {33 * "_id": {"state": "CA", "year": 2010},34 * "populationAvg": 1969000,35 * "state": "CA",36 * "year": 201037 * }, {38 * "_id": {"state": "CA", "year": 2000},39 * "populationAvg": 2240000,40 * "state": "CA",41 * "year": 200042 * }, {43 * "_id": {"state": "FL", "year": 2010},44 * "populationAvg": 320500,45 * "state": "FL",46 * "year": 201047 * }, {48 * "_id": {"state": "FL", "year": 2000},49 * "populationAvg": 278500,50 * "state": "FL",51 * "year": 200052 * }53 * ]54 */