Search...
ascending( )
Adds a sort to a query or sort, sorting by the specified properties in ascending order.
Description
The ascending()
function refines a WixDataQuery
or WixDataSort
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"
. - 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.
Syntax
function ascending(propertyName: ...string): WixDataQuery
ascending Parameters
NAME
TYPE
DESCRIPTION
propertyName
string
The properties used in the sort.
Was this helpful?
Add an ascending sort to a query
Copy Code
1let newQuery = query.ascending("last_name", "first_name");
Create a query, add an ascending sort, and run it
Copy Code
1import wixData from 'wix-data';23// ...45wixData.query("myCollection")6 .ascending("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 found22 }23 })24 .catch((error) => {25 let errorMsg = error.message;26 let code = error.code;27 });
Create a query, add an ascending sort, and run it
Copy Code
1import wixData from 'wix-data';23// ...45wixData.query("myCollection")6 .ascending("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 found24 }25 })26 .catch((error) => {27 let errorMsg = error.message;28 let code = error.code;29 });