3
votes

I am sending formatted date picker value (5/17/2014) in Kendo Grid. In the grid it shows the correct format but after sending, on the server (PHP) it is posted as Sat May 17 2014 00:00:00 GMT+0530 (IST). How do I overcome this from client side it self.

model: {
   id: "id",
    fields: {
    id: {
      editable: false /*type: "number"*/
     },
    schedule_date: {
      type:"date",
      format:"M/d/yyyy"
    },
}

columns: [ {field: "schedule_date", type:"date",   "format": "M/d/yyyy",parseFormats: ["M/d/yyyy"],
title: "Schedule Date",editable: true,width:"200px",
editor: function(container, options) {
                var input = $("<input/>");
                input.attr("name", options.field);
                input.appendTo(container);
                input.kendoDatePicker({
                   "format": "M/d/yyyy",
                    parseFormats: ["M/d/yyyy"],
       });
}}
]
1
Why don't you format it dd/MMM/yyyy. Never any confusion with that irrelevant of lang/culture. - Anthony Horne

1 Answers

0
votes

Even though it displays in M/d/yyyy in the datepicker and in the grid, the value being stored in the grid's data model is still a date object, which is why you are experiencing this issue. A simple, brute force solution would be to go through the data model before sending it out and parse the dates.

var data = $("#gridName").data("kendoGrid").dataSource.view();

for(var i = 0; i < data.length; i++) {
    var date = (data[i].schedule_date.getMonth + 1) + "/" + 
                    data[i].schedule_date.getDate() + "/" +
                    data[i].schedule_date.getFullYear();
    data[i].set("schedule_date", date);
}