【问题标题】:Date format is wrong after posting to server in Kendo Grid在 Kendo Grid 中发布到服务器后日期格式错误
【发布时间】:2014-05-19 11:54:23
【问题描述】:

我在 Kendo Grid 中发送格式化的日期选择器值 (5/17/2014)。在网格中,它显示正确的格式,但在发送后,在服务器 (PHP) 上它被发布为 Sat May 17 2014 00:00:00 GMT+0530 (IST)。我如何从客户端自己克服这个问题。

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"],
       });
}}
]

【问题讨论】:

  • 你为什么不把它格式化为 dd/MMM/yyyy。永远不要混淆与语言/文化无关的东西。

标签: kendo-ui kendo-grid


【解决方案1】:

即使它在日期选择器和网格中显示为 M/d/yyyy,但存储在网格数据模型中的值仍然是一个日期对象,这就是您遇到此问题的原因。一个简单的蛮力解决方案是在发送数据模型并解析日期之前对其进行检查。

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);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-03
    • 2014-02-17
    • 2014-11-10
    • 1970-01-01
    相关资源
    最近更新 更多