Angular ui-grid how to use onRegisterApi in gridOptions

I have an editable table with additional .columnDefs lines. I added a grid api to the table to get an alert when something changed:

$scope.gridOptions.onRegisterApi = function (gridApi) {
        //set gridApi on scope
        $scope.gridApi = gridApi;
        gridApi.edit.on.afterCellEdit($scope, function (rowEntity, colDef, newValue, oldValue) {
            if (newValue !== oldValue) {
                alert('edited row id:' + rowEntity.id + ' Column:' + colDef.name + ' newValue:' + newValue + ' oldValue:' + oldValue);
            }
        });
    };

      

I don't know how to use it in columnDefs. I tried $scope.gridOptions.columnDefs.onRegisterApi = function (gridApi) {}

But it doesn't work. I need to get information about what has changed in these substrings.

+3


source to share


2 answers


$scope.gridOptions.columnDefs.onRegisterApi = function (gridApi) ...

won't work because it's onRegisterApi

not a property columnDefs

- it belongs directly to gridOptions

.



If you want to watch only changes for a specific row / column or some such combination, filter their name (s) in the handler function.

+2


source


I don't see your problem if you want to know which row, column is changed, the correct code is.

gridApi.edit.on.afterCellEdit($scope,function(rowEntity, colDef, newValue, oldValue){
        $scope.msg.lastCellEdited = 'edited row id:' + rowEntity.id + ' Column:' + colDef.name + ' newValue:' + newValue + ' oldValue:' + oldValue ;
        console.log('edited row id:' + rowEntity.id + ' Column:' + colDef.name + ' newValue:' + newValue + ' oldValue:' + oldValue);
        $scope.$apply();
      });

      



Entity String is the data string that was the modifier. ColDef is the exact column that was edited.

Please try again or explain more in your question.

-1


source







All Articles