When you execute a query with the find()
function, it returns a Promise that resolves to a WixDataQueryResult
object.
This object contains the items that match the query, information about the
query itself, and functions for paging through the query results.
Returns the index of the current results page number.
The currentPage
is a zero-based index of the current page of 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.
The currentPage
property returns undefined
if the query returned no results.
let resultPage = results.currentPage; // 0
Returns the items that match the query.
The current page of items retrieved by the query.
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.
When no items match the query, the items
array is empty.
let items = results.items;
/*
* [
* {
* "_id": "1234",
* "_owner": "f45jf8d2-grkj-2opd-4ovk-9rfj4wo5tvj3",
* "_createdDate": "2017-05-29T08:35:52.344Z",
* "_updatedDate": "2017-05-29T08:35:52.344Z",
* "title": "Dr.",
* "first_name": "Jane",
* "last_name": "Doe",
* "status": "active"
* },
* {
* "_id": "5678",
* "_owner": "f45jf8d2-grkj-2opd-4ovk-9rfj4wo5tvj3",
* "_createdDate": "2017-05-25T12:48:56.572Z",
* "_updatedDate": "2017-05-29T07:30:15.869Z",
* "title": "Mr.",
* "first_name": "John",
* "last_name": "Doe",
* "status": "active"
* }
* ]
*/
let resultLength = results.length; // 20
let resultPageSize = results.pageSize; // 50
Indicates if referenced items have been trimmed from the results.
When including a property with multiple references, each returned item can
include up to 50 referenced items. If there are more than 50 referenced items,
only 50 will be returned and partialIncludes
will be true.
To retrieve more than 50 referenced items, use the
queryReferenced()
function.
let partials = results.partialIncludes; // false
Returns the query used to get the current results.
Use the query
property to create and run a new query by chaining additional WixDataQueryBuilder functions to it.
let resultQuery = results.query;
Returns the total number of items that match the query.
The totalCount
returns the total number of items that match the query,
not just the number of items in the current page.
let resultCount = results.totalCount; // 150
let resultPages = results.totalPages; // 3
Indicates if the query has more results.
function hasNext(): boolean;
let hasNext = results.hasNext(); // true
Indicates the query has previous results.
function hasPrev(): boolean;
let hasPrev = results.hasPrev(); // false
Retrieves the next page of query results.
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.
function next(): Promise<WixDataQueryResult>;
oldResults
.next()
.then((results) => {
let newResults = results;
let items = newResults.items;
let firstItem = items[0];
let totalCount = newResults.totalCount;
let pageSize = newResults.pageSize;
let currentPage = newResults.currentPage;
let totalPages = newResults.totalPages;
let hasNext = newResults.hasNext();
let hasPrev = newResults.hasPrev();
let length = newResults.length;
let query = newResults.query;
})
.catch((error) => {
let errorMsg = error.message;
let code = error.code;
});
Retrieves the previous page of query results.
The prev()
function retrieves the previous 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 prev()
the values returned
may change.
Note: The prev()
function is not supported for Single Item Collections.
function prev(): Promise<WixDataQueryResult>;
oldResults
.prev()
.then((results) => {
let newResults = results;
let items = newResults.items;
let firstItem = items[0];
let totalCount = newResults.totalCount;
let pageSize = newResults.pageSize;
let currentPage = newResults.currentPage;
let totalPages = newResults.totalPages;
let hasNext = newResults.hasNext();
let hasPrev = newResults.hasPrev();
let length = newResults.length;
let query = newResults.query;
})
.catch((error) => {
let errorMsg = error.message;
let code = error.code;
});