Sorting/Formating Dates in Grid / Suite 6.0

Hi,

I want a grid displaying a date column in a short format and make ist sortable by clicking the header… unfortunatly i’m really struggling to get this done.

Currently i have Date Objects displayed in the cell, so the output looks like:
“Sat Jun 01 2019 00:00:00 GMT+0200” sorting by clicking on the header works as long as i set the column type to “date”

But i would like to have a output either mm/dd/yyyy or dd.mm.yyyy depending on the language the user choose. Creating just a String naturally breaks the sorting order of the column…

I’ve tried to use the dateFormat option on the date type… but even enabling editing and setting some dates through the datepicker does cause a wrong sorting… 07.11.2010 -> 07.04.2011 -> 13.11.2010

We just recently bought the current version of the suite and i’ve to admin that i’m pretty disappointed after working with it for just two days… documentation seems to miss a lot of stuff and the api is by far not extend as it was in the 5.2 version… really considering to switch to the 5.2 version… any opinions on this?

best regards,
Michael

Hello.

The best way is to create atemplate for your column to change the foramt of the displaying data:
https://docs.dhtmlx.com/suite/grid__usage.html#workingwithcolumnsandcells
Here you can find an example:
https://docs.dhtmlx.com/suite/samples/grid/02_configuration/02_cell_templates.html

Thanks for the help! I’ve tried this and now i have good news and bad news…

Good news: using
template: function(text, row, col) {
return text.toLocaleString(“de”, dateOptions);
}

the cell displays the date in the format i want AND sorting works correctly

Bad news: until i enable editing by adding

type: 'date', dateFormat: '%d.%m.%Y',

to the column and

editing: true,

First of: As soon as I start editing (calender popup) instead of the setup template the “date.tostring” method is displayed and the value in the cell looks like: Sat Jun 01 2019 00:00:00 GMT+0200 instead of 01.06.2019

After selecting a date the sorting falls back to a alphabetical approach…

I’ve tried to implement a custom sorting through grid.data.sort… but it seems that i would have to trigger this manually everytime someone is clicking the column header, parse the string from the datepicker into a date and then compare everything… seems a bit complicated… are there any easier solutions?

Hello.

I apologize for the delay.
The problem with the date column sorting is confirmed. We’ll try to solve it in the future updates.

Thank you for your patience.
The problem is fixed, and the fix is included in the dhtmnlxSuite/grid 6.4 update.