Despite setting a column as type "date" or "datetime" the column sorting applies comparisons based on simple alphanumeric comparisons as if the data was just of type "String."
Expected behavior
Earliest year should display at the top of the sort, not the earliest month
Hi @martindeanlund ,
You are right. I will resolve it asap.
I think it might just be an issue with the example. I was able to sort correctly if the data provided is a proper JS Date and I use "dateTime" as the type for the column definitions, but I have to add Render arguments to convert back to a datestring for display purposes. I don't know if you want to support date strings as the data type and convert them to Date for sorting or support Date for the data type and convert to date Strings for rendering but either should work.
I just look at example at docs now. I will look at code and test it with many cases. I may add support for string dates to be sorted properly. Thanks for giving detailed information
No need improvement.
A solution using Moment.js:
customSort = (a , b) => {
return moment(moment(a[field], [formatDate]))
.isBefore(moment(b[field], [formatDate]))
? 1
: -1;
};
formatDate: here you have to put what is the format of the string date _(ex: 'DD-MM-YYYY - hh:mm A')._