1

Here you can see the binding for a kendo ui grid:

<div data-role="grid" data-bind="source: reportSource, visible: reportVisible"
    data-columns='[{"field":"TIME", "title": "TIME", format: "{0:yyyy-MM-dd hh:mm:ss}", parseFormats: ["yyyy-MM-dd'T'HH:mm:ss"]}, {"field":"LOGIN", "title": "LOGIN"}, {"field":"DEAL", "title": "DEAL"}]'>
</div>

As you see I'm trying to parse dates. I found this solution but when I try to apply this in mvvm binding, the single quotes of 'T' char cause trouble. How can I parse dates in mvvm binding?

Thanks in advance,

Community
  • 1
  • 1
xkcd
  • 2,538
  • 11
  • 59
  • 96
  • 1
    well it seems like you are dealing with just another attribute no ? so maybe try replacing your single quote with ' – G-Man Feb 24 '14 at 14:45
  • @MustafaP I added the solution as an answer. Kolay gelsin. – xkcd Apr 15 '14 at 20:14

3 Answers3

3

Here is the jsfiddle to solve the problem: http://jsfiddle.net/BYqpL/3/ The key point is:

The build-in dataSource data parsing is executed only when the data comes from a transport

and also we have to define the parse method for the field in schema.

"CreatedDate": { 
    type: "date", 
    parse: function(value) { 
        return kendo.parseDate(value, "yyyy-MM-ddTHH:mm:ss");
    }
}
xkcd
  • 2,538
  • 11
  • 59
  • 96
  • Thanks, it works perfect. Sanada kolay gelsin hocam. – MustafaP Apr 16 '14 at 07:14
  • by the way, did you notice when parse function is deleted from CreatedDate, date format stays same. `"format": "{0:dd/MM/yyyy hh:mm:ss}"` works correctly without parse function – MustafaP Apr 17 '14 at 06:28
  • Nope. See the time part of date. It didn't parse correctly the part after "T". I see 12:00:00 in the CreatedDate column which is not the expected value if I remove the parse function. – xkcd Apr 17 '14 at 10:56
0

Since you are dealing with an attribute, try replacing your single quote with

&#39;
G-Man
  • 7,232
  • 18
  • 72
  • 100
0

I was having the same issue and this article helped me alot http://blog.falafel.com/passing-dates-kendo-ui-aspnet/

Changes i made in my code:

  1. in parameterMap

    if (operation === "update" || operation === "create") {

    data.model_date_field = kendo.toString(kendo.parseDate(data.model_date_field), "G");

    return data; }

  2. in model definition

    fields: { model_date_field: { nullable: true, type: "date" } }

Atta H.
  • 661
  • 5
  • 11