2013-04-17 18 views
2

我在將jQuery的日期選擇器和AngularJS ng-grid擴展集成時遇到問題;更具體地說,jQuery日期選擇器無法將數據推回到ng-grid,而是拋出此錯誤:未被捕獲缺少此日期選擇器的實例數據此錯誤消息的所有研究都不涉及其在ng-grid中的使用。在這個小提琴重建jQuery日期選擇器不能使用ng-grid單元

問題:http://jsfiddle.net/ADukg/2363/

任何幫助或解釋將不勝感激。謝謝!

var myApp = angular.module('myApp', ['ui', 'ngGrid']); 

function Ctrl($scope) { 

    $scope.data = [{ 
     "Title": "Title", 
     "Date": new Date("01/03/1970") 

    }]; 

    $scope.kpiGridOptions={data:'data', 
     enableCellEdit:true, 
       columnDefs:[{field:'Title', displayName:'Title'}, 
      {field:'Date', displayName:'Date', editableCellTemplate:'<input ui-date ui-date-format ng-model="row.entity[col.field]">'}] 
    } 
}; 

回答

4

好像你只是有幾個選項不正確。 editableCellTemplate應設置爲true,並且您應該在cellTemplate中指定模板。

http://jsfiddle.net/ADukg/2370/

$scope.kpiGridOptions = { 
    data:'data', 
    enableCellEdit:true, 
    columnDefs: [ 
     { field:'Title', displayName:'Title'}, 
     { field:'Date', displayName:'Date', editableCellTemplate: true, cellTemplate: 
      '<input ui-date ui-date-format ng-model="row.entity[col.field]">' } 
    ] 
} 

此外,爲了在input字段顯示"Date": new Date("01/03/1970")原因沒有默認日期。雖然將分配更改爲字符串表示形式可以解決此問題,您可以在jsfiddle中看到。我沒有時間弄清楚爲什麼現在是這樣,希望這對你來說不是問題。

希望這會有所幫助。