Search.../

ascending( )

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

Description

The ascending() function refines a GuestsQueryBuilder to sort by the value of propertyName in ascending order. You can specify multiple properties for sorting in ascending order by passing each property name as an additional argument. ascending() sorts the results in the order the properties are passed. 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 stored as a string (for example, '0'), that value is sorted alphabetically and not numerically. If a property doesn't have a value, that value is ranked lowest.

Syntax

function ascending(propertyNames: Array<string>): GuestsQueryBuilder

ascending Parameters

NAME
TYPE
DESCRIPTION
propertyNames
Optional
Array<
string
>

Properties used in the sort. To sort by multiple properties, pass properties as additional arguments.

Returns

Return Type:

Was this helpful?

Add an ascending sort to a query

Copy Code
1const query = guests.queryGuests.ascending('_createdDate');
2
Create a query, add an ascending sort, and run it

Copy Code
1import { guests } from 'wix-events.v2';
2
3export async function myQueryFunction() {
4 const results = await guests.queryGuests().ascending('_createdDate').find();
5
6 if (results.items.length > 0) {
7 const items = results.items;
8 const firstItem = items[0];
9 const pageSize = results.pageSize;
10 const hasNext = results.hasNext();
11 const hasPrev = results.hasPrev();
12 const length = results.length;
13 const query = results.query;
14
15 return items;
16 } else {
17 // Handle if no matching items found
18 }
19}
20