Exclude search conditions from wixData query

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:

  • In the Editor using the Number of items to display setting in the Dataset Settings panel.

  • In code using the setPageSize() function.

Through code
https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#setPageSize

Also do you have duplicates in one or both of those used dataset fields? If you have then you will need to code it so that duplicates are not shown etc.

For more on that you can see these previous posts for starters.
https://www.wix.com/corvid/forum/community-discussion/removing-duplicates-in-a-list
https://www.wix.com/corvid/forum/corvid-tips-and-updates/example-remove-duplicates-from-connected-dropdown-options-using-distinct-query
https://www.wix.com/corvid/forum/community-discussion/remove-duplicates-send-to-table-instead-of-dropdown

@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).