Search.../

ascending( )

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

Description

The ascending() function refines a BookingsQueryBuilder to sort in ascending order of the specified properties. 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".

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.

Syntax

function ascending(propertyName: ...string): BookingsQueryBuilder

ascending Parameters

NAME
TYPE
DESCRIPTION
propertyName
string

The properties used in the sort.

Supported properties:

  • startTime
  • _createdDate

Returns

A BookingsQueryBuilder object representing the refined query.

Was this helpful?

Add an ascending sort to a query

Copy Code
1let query = bookings.queryBookings().ascending("startTime", "_createdDate");
Create a query, add an ascending sort, and run it

Copy Code
1import { bookings } from "wix-bookings-backend";
2
3// ...
4
5bookings.queryBookings()
6 .ascending("startTime", "_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 console.error(error);
26 });