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?
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?