dgrid和DateTextBox

时间:2012-11-22 07:50:03

标签: json dojo dgrid

我正在尝试使用dgrid OnDemandGrid来使用dijit.form.DateTextBox作为编辑器。数据通过JSON提供给OnDemandGrid。最初,我试图从MySQL数据库(例如YYYY-MM-DD HH:MM:SS)以原始格式提供日期,但是当DateTextBox似乎无法解析该字符串时,我尝试仅将其提供给日期(例如2012-11-20) 。但是,这也无法奏效。

因此,我的主要问题是让DateTextBox处理日期信息。第二个问题是如何处理时间信息,因为DateTextBox无法编辑时间。我当前的方法是,当我分割SQL日期字符串时,我将dgrid作为dijit.form.TimeTextBox的单独列提供给时间。这似乎是一个混乱的解决方案,所以我愿意接受建议。

这是我的网格代码:

var grid = new declare([OnDemandGrid, Editor, Keyboard, Selection])({
    store: store,
    query: {aid: "1900", action: "objectListGenerator2" },
    bufferRows: 40,
    loadingMessage: "Loading...",
    columns: [
        {field: "oid", label: "Object ID"},
        Editor({field: "startDate", name: "Start Date", editorArgs: { selector: 'date', datePattern: 'yyyy-mm-dd', locale: 'en-us' }}, DateTextBox, "click"),
        Editor({field: "startTime", name: "Start Time"}, TimeTextBox, "click"),
        Editor({field: "endDate", name: "End Date"}, DateTextBox, "click"),
        Editor({field: "endTime", name: "End Time"}, TimeTextBox, "click"),
        {field: "endDateOid", label: "End OID"}
    ],
}, "grid");

以下是我的JSON源代码的示例字符串:

[{"content":"2012-11-20 18:12:00","oid":"2112","author":"","endDateOid":"2113","group":"","endTime":"17:59:00","poid":"0","id":null,"startTime":"18:12:00","gmt":"2012-11-22 00:12:43","name":"The Windows 8 Disaster Rolls On","paid":"1900","endDate":"2012-11-21","type":"startDate","startDate":"2012-11-20","cache":"","cachedate":"0000-00-00 00:00:00"},
{"content":"2013-01-01 17:59:00","oid":"2114","author":"","endDateOid":"2115","group":"","endTime":"16:59:00","poid":"0","id":1,"startTime":"17:59:00","gmt":"2012-11-22 00:14:49","name":"The Windows 8 Disaster Rolls On","paid":"1900","endDate":"2013-01-02","type":"startDate","startDate":"2013-01-01","cache":"","cachedate":"0000-00-00 00:00:00"}]

1 个答案:

答案 0 :(得分:0)

正如我在评论中所指出的,如果我从列定义中删除“click”并因此允许立即创建DateTextBox,则会显示正确的日期。如果稍后添加DateTextBox,我不确定为什么数据没有被正确解析,但至少立即创建它会产生可行的结果。