Hi,
My site is https://devanjanroy.wixsite.com/prime
Could you please help with the following 2 questions:
Q1 - How can I add a date filter so that the user can see the data for a particular date ?
Q2 - How can I sort the data from oldest to newest date? I tried sorting the data on the live database but it is not getting reflecting on the live site.
Hi,
I fixed Q2 by adding the following code, still need help with Q1 
$w(“#dataset1”).setSort( wixData.sort()
.descending(“date”)
Hi devanjanroy,
You can do both using the dataset settings panel and the dataset API (see setFilter ).
Q1 - I guess you want to have a date input, that when changing the value of, the database view changes?
In this case, register an onChange event for the date input (using the property manager) and in the event handler set a filter for the dataset. It should look something like
import wixData from 'wix-data';
export function dateInput_onChange(event) {
$w('#dataset1').setFilter(
wixData.filter()
.gt('date', $w('#dateInput').value)
);
}
Note - the dataInput and dataset1 are ids of the date input and the dataset. You will have to replace them with the ids in your site. To do so, select the dateInput or the dataset and look at the property panel - it is the value at the top of the panel.
Hi Yoav,
Thank you for your explanation. Yes, your code worked perfectly.
However when i replace ‘gt’ with ‘eq’ the code does not work. I would like to display records from the dataset which equals the date input and not greater than the input date.
Is it not working because the data in the collection is stored with a time component ? Is there a way to make it work?
Dates are tricky because of the time stuff.
Best to use a .between operand with start of data and end of day.
let start = new Date($w('#dateInput').value);
start.setHours(0,0,0,0);
let end = new Date($w('#dateInput').value);
end.setHours(23,59,59,999);
$w('#dataset1').setFilter(
wixData.filter()
.between('date', start, end);
);
Yoav I want to do a date filter for a repeater that starts at the current date, and shows everything after it
Hi Brandon,
Simply use Date.now() as the start date