[Solved] Distinct Dropdown List Based on Years

I am needing a little help involving the task of creating a dropdown list that pulls unique / distinct values for years from a database. When someone sends their volunteer hours to this database, I have an additional code that pulls out the specific entry year and places it within a separate column which I have used for various other functions. Now I am trying to use this same column to help populate a dropdown list. It is a number format column instead of text which may be part of my problem. Below is the code I put together based on other discussions and some info Yisrael had posted before. I am still learning this so I am sure I missed something. All the other examples I came across were using text based data for their dropdowns. Any help would be appreciated.

This is the error:
Wix code SDK error: The label parameter of item at index 1 that is passed to the options method cannot be set to the value 2019. It must be of type string.

This is the code:

function buildOptions(items) {
 return items.map(curr => {
 //Use the map method to build the options list in the format {label:uniqueTitle, valueuniqueTitle}
 return { label: curr, value: curr };
    })
}

// Run a query that returns all the items in the collection
    wixData.query("Volunteer_Entries")                                               
 // Get the max possible results from the query 
        .limit(1000)
        .ascending("year")
        .distinct("year")
        .then(results => {
 let distinctList = buildOptions(results.items);
 // unshift() is like push(), but it prepends an item at the beginning of an array
           distinctList.unshift({ "value": '', "label": 'All Years'});
 //Call the function that builds the options list from the unique titles
           $w("#yeardropdown").options = distinctList
    });

Hello Chad,

It is a number format column instead of text which may be part of my problem
This is not “may-be my problem”, it is EXACTLY your problem.
You can not compare apple with bannanas.
The same way it is between NUMBERs and STRINGs.

A DropDown always wants to have STRING-VALUES.

So when you pull out some NUMBERS out of your DATABASE, you have to convert them first to STRINGS and then push them into the DropDown.

(2019).toString // ---> converting into String

From what I am learning, I figured that was the issue and what you said completely makes sense. It helped to know now that dropdowns require string values only. The only thing I found so far is someone referencing:

yourNumber.toLocaleString('en');

Though they did not show a final code for me to look at, from their discussion, would this be part of the code that needs to be incorporated? Would it be before the distinct list code?

OK, I figured out the placement to the string function and it is working properly now. My final code below is what I came up with.

function buildOptions(items) {
 return items.map(curr => {
 //Use the map method to build the options list in the format {label:uniqueTitle, valueuniqueTitle}
 return { label: curr.toString(), value: curr.toString()};
    })
}

// Run a query that returns all the items in the collection
    wixData.query("Volunteer_Entries")                                               
 // Get the max possible results from the query 
        .limit(1000)
        .ascending("year")
        .distinct("year")
        .then(results => {
 let distinctList = buildOptions(results.items);
 // unshift() is like push(), but it prepends an item at the beginning of an array
           distinctList.unshift({ "value": '', "label": 'Available Years'});
 //Call the function that builds the options list from the unique titles
           $w("#yeardropdown").options = distinctList
    });

Well done. I am glad that i could help you :grin:. Another completed mission :wink:

how set dropdown value when click checkbox value?

Please feel free to open your own post, with your own good described issue.

how retrieve data from particular column only