descending( )
Adds a sort to an aggregation, sorting by the items or groups by the specified properties in descending order.
Description
The descending()
function refines a WixDataAggregate
to sort the resulting
items or groups in descending order. If you specify more than one property,
descending()
sorts the results in descending 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 descending(propertyName: ...string): WixDataAggregate
descending Parameters
NAME
TYPE
DESCRIPTION
The properties used in the sort.
Was this helpful?
1let newAggregate = aggregate.descending("state", "city");
1import wixData from 'wix-data';23// ...45wixData.aggregate("PopulationData")6 .group("state", "year")7 .avg("population")8 .descending("populationAvg")9 .run()10 .then((results) => {11 if (results.items.length > 0) {12 let items = results.items; // see below13 let numItems = results.length; // 614 let hasNext = results.hasNext(); // false15 } else {16 // handle case where no matching items found17 }18 })19 .catch((error) => {20 let errorMsg = error.message;21 let code = error.code;22 });2324/* Given the sample data above, items is:25 * [26 * {27 * "_id": {"state": "NY","year": 2010},28 * "populationAvg": 4226500,29 * "state": "NY",30 * "year": 201031 * }, {32 * "_id": {"state": "NY","year": 2000},33 * "populationAvg": 4153500,34 * "state": "NY",35 * "year": 200036 * }, {37 * "_id": {"state": "CA","year": 2010},38 * "populationAvg": 1969000,39 * "state": "CA",40 * "year": 201041 * }, {42 * "_id": {"state": "CA", "year": 2000},43 * "populationAvg": 2240000,44 * "state": "CA",45 * "year": 200046 * }, {47 * "_id": {"state": "FL", "year": 2010},48 * "populationAvg": 320500,49 * "state": "FL",50 * "year": 201051 * }, {52 * "_id": {"state": "FL", "year": 2000},53 * "populationAvg": 278500,54 * "state": "FL",55 * "year": 200056 * }57 * ]58 */