5

頭を悩ませましたが、ng-grid でセル データの変更を検出する方法がわかりません。次のスニペットは、save() を正しく呼び出す ng-change を使用していますが、キー付きエントリに対して呼び出されるため、必要なトリガーではありません。セルの編集がいつ完了するかを知る必要があります。

どんな助けでも大歓迎です。

angular.module('controllers', ['ngGrid']).
controller('ContactsListCtrl', ['$scope', 'Contacts', function ($scope, Contacts) {
    var editableCellTemplate = '<input type="text" ng-class="\'colt\' + col.index" ng-input="COL_FIELD" ng-model="COL_FIELD" ng-change="save()"/>';

    Contacts.get(function(data) {
        $scope.contacts = data;

    });
    $scope.gridOptions = {
        data: 'contacts',
        enableCellSelection: true,
        enableRowSelection: false,
        enableCellEdit: true,
        showSelectionCheckbox: true,
        columnDefs: [
            {field: 'lastName', displayName: 'Last Name', enableCellEdit: true, editableCellTemplate: editableCellTemplate},
            {field: 'firstName', displayName: 'First Name', enableCellEdit: true, editableCellTemplate: editableCellTemplate},
            {field: 'email', displayName: 'EMail Address', enableCellEdit: true, editableCellTemplate: editableCellTemplate},
            {field: 'phone', displayName: 'Phone', enableCellEdit: true, editableCellTemplate: editableCellTemplate}
        ]
    };
    $scope.save = function() {
        $scope.contact = this.row.entity;
        Contacts.save($scope.contact);
    }
}]);
4

6 に答える 6

5

これでうまくいき、セルが編集されたときに完全に編集された行が得られます。その後、保存/更新できます

$scope.$on('ngGridEventEndCellEdit', function(event) {
    $scope.contact = event.targetScope.row.entity;
    Contacts.save($scope.contact);
    // console.log($scope.contact );
});
于 2013-12-13T17:27:40.400 に答える
5

UI Grid 3.0 または 4.x を使用している場合は、待つ必要があります: uiGridEventEndCellEdit

$scope.$on('uiGridEventEndCellEdit', function (data) {
    console.log(data.targetScope.row.entity);
});
于 2015-04-21T00:58:25.440 に答える
1

これが誰かを助けることを願っています。私も ngGridEventEndCellEdit イベントでグリッドの名前が必要でした。

関数内でjqueryを使用:

$scope.$on('ngGridEventEndCellEdit', function (data) {
var gridName = $('.' + data.targetScope.gridId).attr('ng-grid');
});
于 2015-01-05T16:40:04.247 に答える
0

ui-grid 3.0.6 では、afterCellEditイベントを使用しました。

 $scope.gridOptions.onRegisterApi = function (gridApi) {
      $scope.gridApi = gridApi;

      gridApi.edit.on.afterCellEdit($scope,function(rowEntity, colDef,newValue,oldValue){

        if(newValue != oldValue){
          // Do something.......
          // colDef.field has the name of the column that you are editing
        }

      });

}
于 2015-10-07T19:25:02.473 に答える