I’ve created a dropdown menu that is linked to a database on my site. I’ve used the great method here to code this: https://www.wix.com/corvid/forum/tips-tutorials-examples/remove-duplicates-from-connected-dropdown-options?origin=auto_suggest
The dropdown menu displays the category type. The database contains over 4000 rows and these are catalogued into 25 category types. The selection in the dropdown menu is then displayed in a table.
The issue I’m having now is that only 18 of the possible dropdown options are displayed instead of the total of 25 possible options. I wondering whether this is caused by the 1000 limit on the database search. Is there a way to search the whole database field and display all 25 categories?
I’ve seen this possible solution ( https://www.wix.com/corvid/forum/community-discussion/dataset-query-for-3000-items ) but I’m unsure how to build this code into my existing code.
The existing code is as follows:
$w.onReady(function () {
// Run a query that returns all the items in the collection
wixData.query("searchBOXdatabase")
// Get the max possible results from the query
.limit(1000)
.ascending("type")
.find()
.then(results => {
// Call the function that creates a list of unique titles
const uniqueTitles = getUniqueTitles(results.items);
// Call the function that builds the options list from the unique titles
$w("#dropdown1").options = buildOptions(uniqueTitles);
});
// Builds an array from the "Title" field only from each item in
// the collection and then removes the duplicates
function getUniqueTitles(items) {
// Use the map method to create the titlesOnly object containing all the titles from the query results
const titlesOnly = items.map(item => item.type);
// Return an array with a list of unique titles
return [...new Set(titlesOnly)];
}
// Creates an array of objects in the form {label: "label", value: "value"} from the array of titles
function buildOptions(uniqueList) {
return uniqueList.map(curr => {
// Use the map method to build the options list in the format {label:uniqueTitle, value:uniqueTitle}
return {label:curr, value:curr};
});
}
});
export function dropdown1_change(event) {
wixData.query('searchBOXdatabase')
.ascending("type")
.contains('type', $w('#dropdown1').value)
.limit(1000)
.find()
.then(res => {
$w('#table1').rows = res.items;
$w('#table1').show();
});
}
Any help would be very much appreciated.
Many thanks and all best,
Huw
Hey Huw
You are right that this is probably the limit of 1000 on query
Here is a reference on how to do it:
The code should look like this:
$w.onReady(function () {
// Run a query that returns all the items in the collection
retrieveAllItems()
.then(results => {
// Call the function that creates a list of unique titles
const uniqueTitles = getUniqueTitles(results);
// Call the function that builds the options list from the unique titles
$w("#dropdown1").options = buildOptions(uniqueTitles);
});
// Builds an array from the "Title" field only from each item in
// the collection and then removes the duplicates
function getUniqueTitles(items) {
// Use the map method to create the titlesOnly object containing all the titles from the query results
const titlesOnly = items.map(item => item.type);
// Return an array with a list of unique titles
return [...new Set(titlesOnly)];
}
// Creates an array of objects in the form {label: "label", value: "value"} from the array of titles
function buildOptions(uniqueList) {
return uniqueList.map(curr => {
// Use the map method to build the options list in the format {label:uniqueTitle, value:uniqueTitle}
return {label:curr, value:curr};
});
}
});
async function retrieveAllItems(){
let results = await wixData.query("searchBOXdatabase")
.ascending("type")
.limit(1000)
.find();
let allItems = results.items;
while(results.hasNext()) {
results = await results.next();
allItems = allItems.concat(results.items);
}
return allItems;
}
export function dropdown1_change(event) {
wixData.query('searchBOXdatabase')
.ascending("type")
.contains('type', $w('#dropdown1').value)
.limit(1000)
.find()
.then(res => {
$w('#table1').rows = res.items;
$w('#table1').show();
});
}
Please let me know if this helped you.
Best
Binyamin
Thank you so much for your quick reply, Binyamin - very much appreciated.
I’ve added the new code you kindly provided but I’m afraid it hasn’t fixed the issue. The dropdown menu does not open now and there are no items in the dropdown list. Any ideas? Please let me know if I can provide any further information that would help.
Thanks so much,
h
@huwalexander
I’m glad to help
C an you please share the site URL and the specific page so I can take a more in-depth look?
B.
@volkaertskristof @huwalexander
I see it now 
Two mistake
-
Instead of : 'allItems = allItems.concat(result.items);
should be: allItems = allItems.concat(results.items);
-
Instead of: 'const uniqueTitles = getUniqueTitles(results.items); ’
should be: const uniqueTitles = getUniqueTitles(results);
I fixed the original code in my comment,
Let me know if it fixed the issue
B.
@binyaminm
removed my reply,
Whas totaly wrong there, didn’t see the query whas result itself 
@binyaminm Thank you very much. The site URL is:
https://www.textboxdigital.com/
The specific page is https://www.textboxdigital.com/searchbox . The dropdown menu is halfway down the page.
This page is a member only page. Members log in/sign up here: https://www.textboxdigital.com/searchboxhome
I’m afraid the updated fix didn’t work. The dropdown does not appear. I’ve had to put the old code back in for now to keep the dropdown partially working.
Please let me know if you need anything else.
Thanks so much,
Huw
It didn’t update my changes, now the code is up to date
B.
Amazing! It works! Thank you so much for your help, Binyamin. Just brilliant. Can’t thank you enough!
h