Dataset Filter with date

Hi!
I need my dataset to show the results ranked by date, from Old–>New.

The thing is, that when this Rank is set to rank from the New–>Old, the first results to appear are the most recent dates. But when i set to rank by date from Old–>New the first dates to appear are the EMPTY dates… which makes no sense.
I tried to set the dateset filter by condition “not empty”, but it does not has that option. In fact, in the editor, it does not allow us to set filter by date in the dataset (which is possible to do that manualy in the Database screen in the user “desktop”, as seen in the print below).

Any sugestions on how can I set my dataset to show the results ranked by date, from Old–>New?

Hi Felipe,
In order to sort your items according to your own Date field or according to the Default Created Date wix-Field go to sort options in the dataset’s settings.


Have a nice day and best of luck!
Sapir

Hello Sapir.
I know that. But the thing is, when you set to sort by date OLD–>NEW, if there are empty fields in the Date Collumn, the result shown will place the EMPTY DATES as if they where older dates, instead of showing first the dates that are actually older. (That does not happens when you sort the dates form new–>old). I think i wasn’t clear explaining my problem, Sorry.
For my site I must not set the date field as required. Because of that i will have some empty fields.
What I need is that when i execute the dataset in the site it should only show me the lines that have an “argument” (a date) the date field, and that this information is show by the order of old–>new.

Hi Felipe

I believe your Date field’s type is Date&Time , as a result, in order to filter it so that empty fields won’t be shown, and also sort it from old to new, code is required.

Go to the dataset’s properties and add an event handler that runs when the element is ready.
At the function’s handler write the follow code:

export function dataset_ready_1() {
    $w("#dataset1").setFilter(wixData.filter()
            .isNotEmpty("date"))
            .then(() => {
            $w("#dataset1").setSort(wixData.sort()
                .ascending("date")
            )
        })
}

The ascending() function refines a WixDataQuery or WixDataSort to sort in ascending order of the specified properties, and you can also sort type like date and time.
Here, you can read more about this function.

Have a nice day, and best of luck!
Sapir