DavidDunham
DavidDunham

Reputation: 1362

Kendo Grid Date Input Output not properly working

I am working on following example: http://dojo.telerik.com/InEyo

In this example I set the date for the data input to

var date = "2013-10-10 14:02:40.44";

To read the date I use the following where my Date column is defined:

format: "{0:dd-MMM-yyyy HH:mm:ss}",
parseFormats: ["yyyy-MM-dd' 'HH:mm:ss.zz"]

parseFormats defines the format of the input string and format defines how I want to display it (to my understanding). I have my example from Kendo grid format time issue in date column

The example above works - as it should!

My problem (http://dojo.telerik.com/aqafE): The date I get from the database is formatted like this: "20131010 140240" - so "yyyyMMdd HHmmss".

Naturally I would adjust the parseFormats like this:

format: "{0:dd-MMM-yyyy HH:mm:ss}",
parseFormats: ["yyyyMMdd' 'HHmmss"]

However this does not output the date so I assume either I have made a mistake in defining the input string or the string from the database just does not work with Kendo...

Any ideas? Thanks

Upvotes: 1

Views: 1271

Answers (1)

Brian King
Brian King

Reputation: 51

All you need to do in your example is change how your datasource schema defines your model rather than trying to do it on the grid column.

So go from this:

schema: {
    model: {
        fields: {
            Id       : { type: 'number' },
            FirstName: { type: 'string' },
            LastName : { type: 'string' },
            Date: { type: 'date'},
        }
    }
}

To this:

schema: {
    model: {
        fields: {
            Id       : { type: 'number' },
            FirstName: { type: 'string' },
            LastName : { type: 'string' },
            Date     : { type: 'date',
                         parse: function(date) {
                             return kendo.parseDate(date,"yyyyMMdd HHmmss");
                         }
                       }
        }
    }
}

Edit: Here's a fiddle link: http://dojo.telerik.com/aqafE/3

Upvotes: 2

Related Questions