0

I am using Angular ui-grid and am pretty new at it. I receive an array of objects to render data for each row. Each object, hence each row , has a field change:false which marks whether any field on that row has been edited or not. I have kept this field visible : false on screen.

However, whenever any change is made to any column of any row, I want to set this field as change:true.

How can this be achieved on the change of a ui-dropdown field or any other field for that matter.

I have this as my changing column:

{ name: "carrier_influence_group", displayName: "Carrier influence group",  enableCellEdit: true, 
                editableCellTemplate: 'ui-grid/dropdownEditor', type:'object', cellFilter: 'cigFilter', editDropdownValueLabel: 'name',
                editDropownOptionsArray: [{ id: 10, name: 'Small' }, { id: 11, name: 'Medium' }, { id: 12, name: 'Large' }]
                    },

I tried looking for any options available. But couldn't find any way in official docs. Kindly suggest a way or some relevant links

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Saurabh Tiwari
  • 4,632
  • 9
  • 42
  • 82

1 Answers1

1

You can use the afterCellEdit event for this.

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

    gridApi.edit.on.afterCellEdit($scope, function (rowEntity, colDef, newValue, oldValue) {
        if (newValue !== oldValue) {
            rowEntity['change'] = true;
        }
    });
});
S. Baggy
  • 950
  • 10
  • 21
  • It works...Thanks especially for `rowEntity, colDef, newValue, oldValue` arguments. – Saurabh Tiwari Sep 26 '16 at 11:20
  • I still have a issue. What if I want to do something once for a row.?? Currently If I am editing one cell, I want this new row to be pushed in an array. Now after each cellEdit if I push the row, I end up pushing many rows – Saurabh Tiwari Sep 26 '16 at 11:45
  • Thanks for accepting the answer. Does your rowEntity have a unique primary key of some kind? I would just store in the scope an array of IDs already pushed and then only do the push if you don't find the ID in this array. – S. Baggy Sep 26 '16 at 21:23