2016-08-08 144 views
0

我有一個kendo網格自定義編輯器的問題。當我點擊劍道網格上的編輯按鈕時,我想使用dateTimePicker作爲我的編輯器。但是,當我嘗試定製我的dateTimePicker的網格,總有一個錯誤:Kendo Grid內嵌編輯DateTime

Uncaught TypeError: e.indexOf is not a function ---------- kendo.custom.min.js:1 

下面是簡單的源代碼:

var data = [ 
      {"id":1, "dateTime": 1420947900000}, 
      {"id":2, "dateTime": 1421034300000}, 
      {"id":3, "dateTime": 1421036100000}, 
      ]; 
$("#grid").kendoGrid({ 
    selectable: true, 
    editable: "inline", 
    columns: [ 
     { 
      field: "dateTime", 
      title: "<center>Date Time</center>", 
      width: "200px", 
      format: "{0:MM/dd/yyyy hh:mm}", 
      template: "#= kendo.toString(new Date(parseInt(dateTime)), 'MM/dd/yyyy hh:mm') #", 
      editor: dateTimeEditor2 
     }, 
     { command: ["edit", "destroy"], title: "&nbsp;", width: "170px" } 
    ], 
    dataSource: { 
     transport: { 
      read: function(e) { 
       e.success(data); 
      }, 
      update: function(e) { 
       //my update Function 
     alert(e.dateTime); 
      }, 
      autosync: true 
     }, 
     schema: { 
      model: { 
       id: "id", 
       fields: { 
        dateTime: { type: "datetime" }, 
       } 
      } 
     } 
    } 
}); 
function dateTimeEditor2(container, options) { 
    $('<input data-text-field="' + options.field + '" data-value-field="' + options.field 
      + '" data-bind="value:' + options.field + '" />') 
      .appendTo(container) 
      .kendoDateTimePicker({ 
       format:"MM/dd/yyyy hh:mm", 
       value: new Date(options.model.dateTime) 
      }); 
} 

或者你可以檢查這個link

我已經在許多不同的來源檢查過它,例如:

  1. Reference 1
  2. Reference 2

回答

1

你的「日期時間」字段是數字的,但您使用的是網格選項「日期時間」類型。並在編輯器功能,使用上的自定義輸入剎車kendoUI代碼「數據綁定」屬性,因爲它需要某種形式的日期文字我想..

我改變你的代碼更新字段類型爲數字和刪除輸入屬性。錯誤消失了。如果需要使用自定義事件實現DateTimePicker,以便在編輯器值更改時更新grid dataItem的數值。或者也許當「更新」按鈕被點擊在你的例子我想,通過解析datetime值整數和設置網格的DataItem ..

http://dojo.telerik.com/ecICE

額外注: 我還要考慮我的操縱數據源陣列,以改變將這些數值綁定到網格之前將其轉換爲JS日期時間值。這可能是更簡單的解決方案。

-