Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

detect cell edit in angular ui-grid

I try to detect cell edit but the following code does not get event. I use "name": "angular-ui-grid", "version": "3.0.0-rc.14", Do I have to define some configuration to get events?

$scope.$on('ngGridEventEndCellEdit', function(data) {
like image 812
vertti Avatar asked Mar 07 '15 21:03

vertti


Video Answer


2 Answers

I updated the default row template to look like below

rowTemplate: '<div ng-class="{\'row-changed\':row.entity.State==\'changed\'}" ng-click="grid.appScope.fnOne(row)" ng-repeat="col in colContainer.renderedColumns track by col.colDef.name" class="ui-grid-cell" ui-grid-cell></div>',

And then in onRegisterApi

onRegisterApi: function( gridApi ) {
            $scope.gridApi = gridApi;
            $scope.gridApi.edit.on.afterCellEdit($scope,function(rowEntity, colDef, newValue, oldValue){
                if(newValue != oldValue)
                    rowEntity.State = "changed";
            })
        }

The row will now get the class "row-changed" if the entity has the State "changed".

You might want to add some extra checks if the cell gets changed back to its original value, but that's another issue.

like image 63
Roger Avatar answered Sep 21 '22 06:09

Roger


You can use the beginCellEdit event:

gridApi.edit.on.beginCellEdit($scope, function(rowEntity, colDef) { ... });
like image 33
btk Avatar answered Sep 20 '22 06:09

btk