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

And JSON DateTime fields again

4 Answers 535 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Vitaly
Top achievements
Rank 1
Vitaly asked on 10 Mar 2015, 09:46 PM
Hi.
In response from server (which function return Json(some_records, JsonRequestBehavior.AllowGet)) I have field:
TestDate: "2015-03-11T02:10:27.8278798+05:00"
If I don't specify 'schema' for kendo-grid then TestDate colimn's cells displays string values 'as is'. There not enable date formating, sorting and filtering, of course.
But when I specify
    schema  : {
            model: {
                fields: {
                    TestDate: { type: 'date' }
                }
            }
        }
all column's cells values become empty.
Why is that?
I've tried specify format and parseFormats - it's not working.
Template "#= kendo.parseDate(TestDate, 'yyyy-MM-ddTHH:mm:ss.fffZ') #" for column returns 'null' everytime (with any parse format I set).
I get example here http://jsfiddle.net/OnaBai/Ahq6s/ and input "2015-03-11T02:10:27.8278798+05:00" in date field.. and it works!

After hours I come up with a solution - specify template "#= new Date(TestDate).format('dd.mm.yyyy') #".
Huray, my TestDate is displayed! But only if I don't specify TestDate type in schema.model.fields. And without that I don't have date options in filtering menu, for example.
What I do wrong?

P.S. Oh, and one more thing. In demo http://demos.telerik.com/kendo-ui/grid/filter-row we see 4 column specified in code and only 3 columns in visual grid.
Guess, which column is not displayed? Yup, 'OrderDate' with type: 'date' in schema.model.fields description. Same result in Dojo.
I don't know what to think.

P.P.S. Sorry for my English.

4 Answers, 1 is accepted

Sort by
0
Vitaly
Top achievements
Rank 1
answered on 11 Mar 2015, 05:19 AM
Conserning demo I mentioned - it's something wrong with horizontal scrolling, not with date column, because in dojo by default I can't see that column in grid, but after I shrink left panel with code to minimum width that column is wonderfully appeared. Screenshots are attached.

Sorry for misleading )
0
Vitaly
Top achievements
Rank 1
answered on 11 Mar 2015, 06:19 AM
And it's me again, all alone ))
I've tried to use some manipulations with DateTime field on server side and found, that if I truncate date to seconds then in response I get 
TestDate: "2015-03-11T02:10:27"
and grid's column with this field works precisely as it must.

As soon as milliseconds appears in date field I get
TestDate: "2015-03-11T02:10:27.892"
in JSON response and column's cell displays nothing.

Can anyone give the cue where in kendo scripts I can correct date parsing?
0
Accepted
Rosen
Telerik team
answered on 12 Mar 2015, 03:48 PM
Hi Vitaly,

If when setting the schema.field.type to date the value is set to null, this means that the string value passed from the server does not match the supported date formats of the kendo.parseDate. As you may know by default, this method will be used to convert the server string value to the Date instance. If you want to use some custom format you will need to set the parse function of the field to handle this parsing manually. Similar to the following:

schema  : {
    model: {
        fields: {
            TestDate: { type: 'date', parse: function(value) { return kendo.parse(value, "MY_CUSTOM_FORMAT"); } }
        }
    }
}


Regards,
Rosen
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Vitaly
Top achievements
Rank 1
answered on 16 Mar 2015, 06:21 AM
Hi Rosen. Thank you for answer.

I've tried to use parsing function in TestDate field settings:

schema  : {
    model: {
        fields: {
            TestDate: { type: 'date', parse: function(value) { return kendo.parse(value,"yyyy-MM-ddTHH:mm:ss.fffZ"); } }       
        }   
    }
}

but got exception on executing kendo.parse(...).
Well, I got exception even if I try to parse exact value, like this:
return kendo.parse("2015-03-11T02:10:27", "yyyy-MM-ddTHH:mm:ss");

I don't know why. If it's necessary I'll post stack trace on exception.

So, I've replaced kendo.parse() on new Date() function and it's working.

Thanks for the tip!
Tags
Grid
Asked by
Vitaly
Top achievements
Rank 1
Answers by
Vitaly
Top achievements
Rank 1
Rosen
Telerik team
Share this question
or