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.

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

Code Example

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.

Code Example

Copy Code
1async function retrieveAllItems(phrase){
2 let allItems = [];
3
4 let results = await wixData.query("myCollection")
5 .limit(1000)
6 .find();
7
8 allItems.push(results.items);
9
10 while(results.hasNext()) {
11 results = await results.next();
12 allItems.push(results.items);
13 }
14 return allItems;
15}
16