为什么格式化我的KendoGrid列不工作

Why is formatting my KendoGrid columns not working?

本文关键字:工作 KendoGrid 格式化 我的 为什么      更新时间:2023-09-26

我正在学习剑道UI,并遵循其中一个演练。我有一个网格工作,但日期格式不工作,由于某种原因。

$("#archiveGrid").kendoGrid({
    columns: [
        { field: "SentDate", title: "Sent", format: "{0:MM/dd/yyyy}" },
        { field: "SenderName", title: "Sender" },
        { field: "SenderEmail", title: "Email" },
        "Subject"
    ],
    dataSource: new kendo.data.DataSource({
        transport: {
            read: "api/messages"
        },
        pageSize: 15,
        serverPaging: true,
        schema: {
            data: "Data",
            total: "Count"
        }
    }),
    pageable: true
});

但是我的约会对象仍然看起来像2014-02-07T21:06:03.993。我测试了网格忽略format属性的理论,并将格式字符串更改为"foo {0:MM/dd/yyyy}",这使得日期显示为foo 2014-02-07T21:06:03.993

我做错了什么?

您缺少DataSource中的模型。尝试添加一个合适的模型,并将类型设置为date。然后格式将正常工作,也不要忘记提到id。

schema: {
                id: "Id",
                data: "Data",
                total: "Count",
                fields: {
                        SentDate: { editable: true, type: "date"},
                        SenderName: { editable: true},
                        SenderName: { editable: true}
                    }
            }