Search.../

next( )

Retrieves the next page of query results.

Description

The next() function retrieves the next page of query results.

The page size is defined by the limit() function, can be retrieved using the pageSize property, and navigating through pages is done with the prev() and next() functions.

If items are added or removed between calls to next() the values returned by WixDataQueryResult may change.

Note: The next() function is not supported for Single Item Collections.

Syntax

function next(): Promise<WixDataQueryResult>

next Parameters

This function does not take any parameters.

Returns

Fulfilled - A query result object with the next page of query results. Rejected - The errors that caused the rejection.

Return Type:

Was this helpful?

Get the next page of a query result

Copy Code
1oldResults.next()
2 .then((results) => {
3 let newResults = results;
4 let items = newResults.items;
5 let firstItem = items[0];
6 let totalCount = newResults.totalCount;
7 let pageSize = newResults.pageSize;
8 let currentPage = newResults.currentPage;
9 let totalPages = newResults.totalPages;
10 let hasNext = newResults.hasNext();
11 let hasPrev = newResults.hasPrev();
12 let length = newResults.length;
13 let query = newResults.query;
14 })
15 .catch((error) => {
16 let errorMsg = error.message;
17 let code = error.code;
18 });
Iterate through all pages of query results

This example demonstrates how to get all query results, bypassing the maximum limit of 1000.

Copy Code
1async function retrieveAllItems() {
2 let results = await wixData.query("myCollection")
3 .limit(1000)
4 .find();
5 let allItems = results.items;
6 while (results.hasNext()) {
7 results = await results.next();
8 allItems = allItems.concat(results.items);
9 }
10 return allItems;
11}