imperium2335
imperium2335

Reputation: 24132

Kendo UI Grid long date on update

In my grid I have a date column with the following parameters:

update: {
            url: ROOT+"user/update-user",
            type: "POST"
        }

columns: [
    {...},
    {
        field: "DoB",
        width: 68,
        title: "DoB",
        format: "{0:dd/MM/yyyy}",
        template: '#= kendo.toString(DoB,"dd/MM/yyyy") #'
    },
    {...}

datasource: {
    ...
    schema: {
        model: {
            DoB: {type: "date", editable: false, format: "{0:dd/MM/yyyy}"},
        }
    }
}

The problem is, is that when I try to update the date column it is sending a really long date instead of the SQL style date "YYYY-MM-DD":

Wed Jan 09 2003 00:00:00 GMT +0000 etc

Any idea what is causing this?

Upvotes: 1

Views: 2275

Answers (1)

OnaBai
OnaBai

Reputation: 40917

The reason is because when KendoUI is about to send data to the server it serializes your data to string and default serialization for date type is the long format.

You can adapt you data for sending it to the server by defining a transport.update as:

update: {
    url : ROOT + "user/update-user",
    type: "POST",
    data: function (data) {
        data.DoB = kendo.toString(data.DoB, "yyyy-MM-dd");
        return data;
    }
},

NOTE you might need some extra validation for making sure that DoB is actually defined

Upvotes: 6

Related Questions