Search.../

descending( )

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

Description

The descending() function refines a PublicPlansQueryBuilder 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".

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. When sorting, ascending order is: numbers, followed by symbols, and then letters.

Syntax

function descending(propertyName: ...string): PublicPlansQueryBuilder

descending Parameters

NAME
TYPE
DESCRIPTION
propertyName
string

The properties used in the sort.

Supported properties:

  • primary
  • slug
  • _createdDate
  • _updatedDate

Returns

A PublicPlansQueryBuilder object representing the refined query.

Was this helpful?

Add a descending sort to a query

Copy Code
1const query = wixPricingPlansBackend.queryPublicPlans().descending("_createdDate");
Create a query, add a descending sort, and run it

Copy Code
1import wixPricingPlansBackend from 'wix-pricing-plans-backend';
2
3// ...
4
5wixPricingPlansBackend.queryPublicPlans()
6 .descending("_createdDate")
7 .find()
8 .then((results) => {
9 if (results.items.length > 0) {
10 const items = results.items;
11 const firstItem = items[0];
12 const totalCount = results.totalCount;
13 const pageSize = results.pageSize;
14 const currentPage = results.currentPage;
15 const totalPages = results.totalPages;
16 const hasNext = results.hasNext();
17 const hasPrev = results.hasPrev();
18 const length = results.length;
19 const query = results.query;
20 } else {
21 // handle case where no matching items found
22 }
23 })
24 .catch((error) => {
25 const queryError = error;
26 });