Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Toar on Nov 18, 2007 05:33
open dhtmlx forum
Sorting date in a custom format

Hi,

I've been experimenting with dhtmlxgrid. I want to know if I can sort date that uses custom format, such as dd-MM-yyyy or MM-dd-yyyy.
Answer posted on Nov 19, 2007 01:19
You can

a) use "calendar" or "dhxCalendar" excells , they allow usage of setDateFormat command , which allow to define custom output format, while preserving correct sorting|editing

or

b) You can define custom sorting functionality which will compare dates in your format
Answer posted by Toar on Nov 20, 2007 19:49
I'm interested in using the second option, because I can extend the grid even more, not only using sort for custom date format, but I can use it for custom data type format.
Where can I modified the sort definition so I can initialize the grid like this :
mygrid.setColSorting("customdate,customdata");


Answer posted on Nov 21, 2007 02:39
>>Where can I modified the sort definition so I can initialize the grid like this :

There is no need to customization in source code it will look as

mygrid.setColSorting("customdate,customdata");
function customdate(a,b,order){
    //a,b - values which need to be compared
    a=custom_decode_date(a) //your custom code here
    b=custom_decode_date(b) //your custom code here

    if (order=="asc")
        return a>b?1:-1;
    else
        return a>b?-1:1;

}