Search.../

descending( )

Adds a sort to a query or sort, sorting by the specified properties in descending order.

Description

The descending() function refines a WixDataQuery or WixDataSort to sort in descending order of the specified properties. 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 before "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.

Authorization

Request

This endpoint does not take any parameters

Response Object

A WixDataQuery object representing the refined query.

Returns an empty object.

Status/Error Codes

Was this helpful?

Add an descending sort to a query

Copy Code
1let newQuery = query.descending("last_name", "first_name");
Create a query, add an descending sort, and run it

Copy Code
1import wixData from 'wix-data';
2
3// ...
4
5wixData.query("myCollection")
6 .descending("last_name", "first_name")
7 .find()
8 .then((results) => {
9 if(results.items.length > 0) {
10 let items = results.items;
11 let firstItem = items[0];
12 let totalCount = results.totalCount;
13 let pageSize = results.pageSize;
14 let currentPage = results.currentPage;
15 let totalPages = results.totalPages;
16 let hasNext = results.hasNext();
17 let hasPrev = results.hasPrev();
18 let length = results.length;
19 let query = results.query;
20 } else {
21 // handle case where no matching items found
22 }
23 })
24 .catch((error) => {
25 let errorMsg = error.message;
26 let code = error.code;
27 });
Create a query, add an descending sort, and run it

Copy Code
1import wixData from 'wix-data';
2
3// ...
4
5wixData.query("myCollection")
6 .descending("last_name", "first_name")
7 .eq("status", "active")
8 .limit(10)
9 .find()
10 .then((results) => {
11 if(results.items.length > 0) {
12 let items = results.items;
13 let firstItem = items[0];
14 let totalCount = results.totalCount;
15 let pageSize = results.pageSize;
16 let currentPage = results.currentPage;
17 let totalPages = results.totalPages;
18 let hasNext = results.hasNext();
19 let hasPrev = results.hasPrev();
20 let length = results.length;
21 let query = results.query;
22 } else {
23 // handle case where no matching items found
24 }
25 })
26 .catch((error) => {
27 let errorMsg = error.message;
28 let code = error.code;
29 });