ngGrid:无法使用cellTemplate捕获输入

时间:2014-06-19 11:07:37

标签: angularjs ng-grid

我正在尝试使用ngGrid来捕获数据。在$scope.myData列的CellTemplate上输入输入时,我很难在提交时获得更新age

问题:

如何使用cellTemplate捕获数据并在sumbit上获取更新的$scope.myData



网格A

enter image description here

JS

     $scope.myData = [{name: "Moroni", age: ""},
                   {name: "Tiancum", age: ""},
                   {name: "Jacob", age: ""},
                   {name: "Nephi", age: ""}];

  $scope.gridOptions = { 
    data: 'myData',
    selectedItems: $scope.mySelections,
    multiSelect: true,
    columnDefs: [
      {field: 'name', displayName: 'Name'},
      {field:'age', displayName:'Age', cellTemplate: '<input type="number" placeholder="Enter age" />'}
    ]
  };

  $scope.getUpdatedData = function () {
    console.log($scope.myData);
    $scope.updatedData = $scope.myData;
  };




网格B 但是,没有一个cellTemplate

enter image description here

JS

// WITHOUT CELL TEMPLATE
  $scope.myData2 = [{name: "Moroni", age: ""},
                   {name: "Tiancum", age: ""},
                   {name: "Jacob", age: ""},
                   {name: "Nephi", age: ""}];

  $scope.gridOptions2 = { 
    data: 'myData2',
    selectedItems: $scope.mySelections,
    enableCellEditOnFocus: true,
    multiSelect: true,
    columnDefs: [
      {field: 'name', displayName: 'Name'},
      {field:'age', displayName:'Age'}
    ]
  };

  $scope.getUpdatedData2 = function () {
    console.log($scope.myData2);
    $scope.updatedData2 = $scope.myData2;
  };



Plnkr: http://plnkr.co/edit/vey5tGBEcnYJYyUZasg8?p=preview

1 个答案:

答案 0 :(得分:1)

如果你放

就可以了
<input type="number" placeholder="Enter age" ng-input="COL_FIELD" ng-model="COL_FIELD" />

作为您的cellTemplate。我已更新your plunk以证明这一点。