This is a migrated thread and some comments may be shown as answers.

Date Sorting Not Working as Expected

14 Answers 2577 Views
Grid
This is a migrated thread and some comments may be shown as answers.
jeff
Top achievements
Rank 1
jeff asked on 02 Apr 2015, 10:40 AM
Hi folks,
We use a date format of d-MMM-yyyy ( format: {0:d-MMM-yyyy}, etc..  ), but I haven't had any luck getting it to sort correctly, please review my fiddle:

http://jsfiddle.net/crunchfactory/dje9n6u9/

Bug? Do I need to do something different?

Thank you,

j

14 Answers, 1 is accepted

Sort by
0
Accepted
Boyan Dimitrov
Telerik team
answered on 03 Apr 2015, 01:44 PM

Hello Jeff,

The problem in this case that the dates are treated as strings objects and they are compared as plain text. 

A possible solution is to parse them to dates so the filtering will work as expected. Please refer to this dojo example

Regards,
Boyan Dimitrov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
jeff
Top achievements
Rank 1
answered on 03 Apr 2015, 04:31 PM
I apologize, I thought I _was_ parsing them, but clearly only getting string-sorted results, :D

Where I'm having this issue is inside the detailRow of an mvvm grid, which is also mvvm; how do I get it to see the sort function, etc..?
0
Boyan Dimitrov
Telerik team
answered on 07 Apr 2015, 08:42 AM

Hello Jeff,

Setting sortable should work out of the box. Could you please prepare sample dojo example in order to demonstrate the problem? 

Regards,
Boyan Dimitrov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
jeff
Top achievements
Rank 1
answered on 07 Apr 2015, 10:25 AM

Hi Boyan,

Please review:

http://dojo.telerik.com/@crunchfactory/UqIKo

As you can see, it's not sorting correctly at all (note the month/year); is it the date format I'm using, or am I missing something very, very obvious here? It only appears to be sorting it as a string.

 

Thank you!

0
Boyan Dimitrov
Telerik team
answered on 08 Apr 2015, 06:36 AM

Hello Jeff,

As I mentioned earlier the dates in your case are treated as string objects. In order to parse them to date object please use the data source schema.parse as shown below:

 

schema: {
            model: {
              fields: {
                OrderDate: {
                  type: "date",
                  parse: function (e) {
                    return new Date(e)
                  }
                }
              }
            }
          },

Also please refer to the modified version of the provided dojo code  http://dojo.telerik.com/@boyan.dim/aFuKO

 

Regards,
Boyan Dimitrov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
jeff
Top achievements
Rank 1
answered on 08 Apr 2015, 11:43 AM

Hi Boyan,

To be fair, true, I forgot to place the parse function in the dojo demo, however, have been using it inside the datasource for a mvvm detailRow; 

 

detailRow.find("#userGrid").kendoGrid({
                dataSource: {
                    serverPaging: false,
                    schema: {
                        data: "data",
                        total: "total",
                        model: {
                            fields: {
                              Date: {
                                type: "date",
                                parse: function (e) {
                                  return new Date(e)
                                }
                              }
                            }
                          }
                    },
                    pageSize: 10,
                    transport: {
                        read: function(options) {
                        }
                    },
                    update: function() {}
                }, //etc...

 

The 'Date' in question, is inside a nested observable json array like this:

"fancyQueue": [{
                "Approver": "Smith, John",
                "Role": "Manager",
                "Date": "16-Mar-2015",
                "Status": "Approved"
        }], //etc...

It is still treating it as a string; what am I missing here?

Again, thank you very much!

0
Boyan Dimitrov
Telerik team
answered on 10 Apr 2015, 07:55 AM

Hello Jeff,

Please refer to the following dojo example. Please try to modify it in order to replicate the problem. 

Regards,
Boyan Dimitrov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
jeff
Top achievements
Rank 1
answered on 13 Apr 2015, 01:15 PM

Hello Boyan,

Is there some way I can post my code to you privately, in a dojo or fiddle or something? 

Thank you!

0
Accepted
Boyan Dimitrov
Telerik team
answered on 14 Apr 2015, 03:04 PM

Hello Jeff,

 

One possible solution would be to open a support ticket and either attach an isolated runnable example or provide a dojo link. The communication in support tickets is completely private. 

 

Regards,
Boyan Dimitrov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
jeff
Top achievements
Rank 1
answered on 14 Apr 2015, 06:04 PM

Hi Boyan,

Thank you, very good advice, I've created a ticket for a few items, and included the entire file (however messy, lol!) to help troubleshoot. 

Thank you very much!

0
jeff
Top achievements
Rank 1
answered on 20 Apr 2015, 10:29 PM

Hi Boyan!

I've found a significant part of the issue; on the date sorting in:

http://dojo.telerik.com/@boyan.dim/UDAWE

It works great in Chrome, but the date in Firefox and Internet Explorer 9-11 returns not a number; NaN-M-0NaN

Has this been seen before? Any suggestions?

Thank you very much!

 

0
jeff
Top achievements
Rank 1
answered on 21 Apr 2015, 03:56 PM
Ok, they also changed date format, but with internal parser:

dateAdded: { type: "date", parse: function (e) {
 return kendo.parseDate(e, 'dd-MMM-yy');
}},

 

and then:

{ field: "dateAdded", title: "Date Added", width: "100px", type: "dateTime", format: "{0:dd-MMM-yy}" }

Thank you Boyan

0
Accepted
Boyan Dimitrov
Telerik team
answered on 22 Apr 2015, 03:15 PM

Hello Jeff,

Could you please clarify whether you have resolved the problem or the issue still persists?

Regards,
Boyan Dimitrov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
jeff
Top achievements
Rank 1
answered on 22 Apr 2015, 07:45 PM

Hi Boyan,

Yes, it's resolved, using the internal date parser:

return kendo.parseDate(e, 'dd-MMM-yy');

 

Thank you!

Tags
Grid
Asked by
jeff
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
jeff
Top achievements
Rank 1
Share this question
or