I’m using the query below to populate a table. All of the filters are optional to the user - they can choose to enter no filters and get all the data back, or they can enter a title to filter by title, or both title and city…and so on.
I’m having trouble when the user chooses to omit one of the filters. For example, with “state” = AZ I expect to return 20 results, but I only get 10. I’ve tried passing the title and city in as undefined, null, and “”, none of which return the full 20 results.
Please help!
wixData.query("My-Collection")
.contains("title", title)
.contains("city", city)
.contains("state", state)
.find()
.then(res => {
$w("#table1").rows = res.items;
});
Have you read about using or from the Wix Data Query in Wix Data API.
https://www.wix.com/corvid/reference/wix-data.WixDataQuery.html#or
I tried the snippet below and had a different issue - I expect to return only 20 results for AZ, but am seeing more than that.
wixData.query("My-Collection")
.contains("title", params.title)
.or(wixData.query("My-Collection").contains("state", state))
.find()
.then(res => {
$w("#table1").rows = res.items;
});
If you are getting way too many results being shown at one time, then you can set up your dataset to only show a certain amount.
For tables -
If you have connected the table through a Data Set you can set the LIMIT property in that data set. Just click Manage Dataset and set the limit. Then you can add a pagination element, connect that to the same data set and you are up and running.
https://www.wix.com/corvid/reference/$w.Pagination.html
Through code
https://www.wix.com/corvid/reference/$w.Table.html#pagination
https://www.wix.com/corvid/reference/$w.Table.html#PaginationOptions
For repeaters -
https://www.wix.com/corvid/reference/wix-dataset.html#data-paging
Dataset Pages
Datasets retrieve information from your collections in chunks of items. Each of these chunks is called a page.
A dataset’s page size determines how many items are initially displayed in repeaters that are connected to it. Elements that have their own settings for how many items are shown at once, such as tables and galleries, are not affected by the dataset’s page size.
Elements that display data from the dataset’s current item, such as images and text elements, are affected when you change the current dataset page because the dataset’s current item also changes.
You set the page size of a dataset:
Through code
https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#setPageSize
@givemeawhisky The problem isn’t in displaying a certain number of results, it’s that I can’t create a query that returns the set of results that I expect. If I go directly to the collection, I can apply a filter at the top of the page by state and it returns only 20 results. When I try to reproduce this query using wixData, I either get fewer than 20 results (from the first code snippet) or greater than 20 results (from the second code snippet).