[SOLVED] Search a database based on date: _createdDate

Hi, I’d like to create a dropdown list sort of _createdDate. Can you please help me to verify the code?


$w.onReady(function () {
    uniqueDropDown1();
});

function uniqueDropDown1 (){

    wixData.query("All_Votes").descending("_createdDate")
      .contains("_createdDate", $w("#datePicker2").value)
      .limit(1000)
      .find()
      .then(results => {
            console.log (results)
 const uniqueTitles = getUniqueTitles(results.items);
 
           $w("#datePicker2").value = buildOptions(uniqueTitles);
      });

 function getUniqueTitles(items) {
 const titlesOnly = items.map(item => item._createdDate);
 return [...new Set(titlesOnly)];
    }

 function buildOptions(uniqueList) {
 return uniqueList.map(curr => {
 return {label:curr, value:curr};
        });
    }
}

This post could be interessting for you…
https://www.wix.com/velo/forum/community-discussion/help-on-connecting-repeater-to-a-filtered-dropdown-via-dataset

Thank you for a link, but I need to make a dropdown menu from collection system record _createdDate. The idea is to sort of the records based on created date. Unfortunately, I can’t find any related post…:frowning:

@jankucera
Ok, for this case, my filter-engine is not prepared.

I think, i have to improve my interactive example, hmmmm ok.

@russian-dima In fact, my use case is not based on repeater, but to show created date in dropdown menu (of course with readable format…:))

@jankucera
I don’t know if this is what you want, but take a look on it…
https://www.media-junkie.com/ranking-system

I implemented into this example, a “sort by-date-function”.

@russian-dima This function works for the table, but I’d like to but the result of created date to dropdown menu. User can select from dropdown list specific date! Is it feasible?

Hi @jankucera
Does the dropdown works?
From what i can see it looks good.
Are there any errors you have?

kind regards,
Kristof.

@volkaertskristof for better undesrasting of my use case I attached the screenshot…

@jankucera
I think i see the problem :smiley:

$w.onReady(function () {
    uniqueDropDown1();
});



function uniqueDropDown1 (){

    wixData.query("All_Votes").descending("_createdDate")
      .contains("_createdDate", $w("#datePicker2").value)
      .limit(1000)
      .find()
      .then(results => {
            console.log (results)
 const uniqueTitles = getUniqueTitles(results.items);
 
           $w("#datePicker2").value = buildOptions(uniqueTitles); //<-- shouldn't $w("#dataPicker2").value be your dropdown instead?
      });

 function getUniqueTitles(items) {
 const titlesOnly = items.map(item => item._createdDate);
 return [...new Set(titlesOnly)];
    }

 function buildOptions(uniqueList) {
 return uniqueList.map(curr => {
 return {label:curr, value:curr};
        });
    }
}

Added an arrow with comment in red

so:

$w("#datePicker2").value = buildOptions(uniqueTitles);

i think it should be

$w("#yourDropdown").options= buildOptions(uniqueTitles);

@volkaertskristof unfortunately, this use case works for non system value (like title) , but not works for system collection record (field): _createdDate…:frowning:

here is a code:

import wixData from 'wix-data';

$w.onReady(function () {
    uniqueDropDown1();
});

//------------------------------------------------------SELECT DATE---------------
function uniqueDropDown1 (){

    wixData.query("All_Votes")
      .contains("_createdDate", $w("#dropdown1").value) // filter all old Dates out
      .limit(1000)
      .find()
      .then(results => {
            console.log (results)
 const uniqueTitles = getUniqueTitles(results.items);
           $w("#dropdown1").options = buildOptions(uniqueTitles);
      });

 function getUniqueTitles(items) {
 const titlesOnly = items.map(item => item._createdDate);
 return [...new Set(titlesOnly)];
    }

 function buildOptions(uniqueList) {
 return uniqueList.map(curr => {
 return {label:curr, value:curr};
        });
    }
}

@jankucera

This function works for the table, but I’d like to but the result of created date to dropdown menu. User can select from dropdown list specific date! Is it feasible?
As you already mentioned it. If it works in tables, why not use the table to select your wished VALUE? :wink: (using table as a dropdown) :grin:

Hi, any idea hot to show the dates in dropdown menu? It seems that only string can be in dropdown menu. What do you think?

@russian-dima The reason why I need to have the date in dropdown menu is that I want to sort of the meetings based on date or month.

@jankucera

try it like this

.then(results=>{            
console.log(results)
getUniqueTitles(results.items)
.Then(res=>{
$w("#dropdown1").options =buildOptions(res);});
})

And maybe change this aswel

return{label:curr, value:curr};
To
return{label:curr.toString(), value:curr.toString()};

Try the second part after you tried the first part.

@volkaertskristof unfortunately it doesn’t works

wixData.query(“All_Votes”)
.ge(“_createdDate”, $w(“#dropdown1”).value)
.limit(1000)
.find()
.then(results => {
console.log (results)

   getUniqueTitles(results.items) 
    .than (res=> { 
    $w("#dropdown1").options = buildOptions(res);}); 

  }) 

function getUniqueTitles(items) {
const titlesOnly = items.map(item => item._createdDate)
return […new Set(titlesOnly)];
}

function buildOptions(uniqueList) { 
    return uniqueList.map(curr => { 
        return {label:curr, value:curr}; 
    }) 
} 

}

Did you also tried the part to adding to it?

And now you are comparing shares with dropdown1 and later you are changing dropdown 1?