2

I am using ui-grid for grid. I want to create a grid with some columns from the database and an extra column for a button.

    $scope.studentgrid = {
    data: 'students',
    enableFiltering: false,
    onRegisterApi: function(gridApi){
        $scope.gridApi = gridApi;
        $scope.gridApi.grid.registerRowsProcessor( $scope.singleFilter, 200 );
    },

    enableRowSelection: true,
    multiSelect: false,
    enableColumnResizing: true,
    enableSelectAll:true,
    enableCellEdit: false,
    enableFullRowSelection: true,
    enableCellEditOnFocus: false,        
    columnDefs: [
        { field: 'ID'},
        { field: 'name'},
        { field: 'age' },
        { field: 'email', displayName: 'Email(Sorting Disabled)', enableSorting: false },
        { field: 'Change', cellTemplate: '<div><button ng-click="grid.appScope.genalert()">Click Here</button></div>'}
    ]
};

In ui-grid, I have register a callback function on the event rowSelectionChanged

$scope.studentgrid.onRegisterApi = function (gridApi) {
    $scope.gridApi = gridApi;
    gridApi.selection.on.rowSelectionChanged($scope, function (row) {
        alert(row.isSelected);
    });
};

Each time when I click on the button the rowSelectionChanged event is firing. How can I stop rowSelectionChanged event to be fired when I click on button? I need enableFullRowSelection to be true.

Yasin Okumuş
  • 2,299
  • 7
  • 31
  • 62

1 Answers1

0

I have not found a way to swallow the rowSelectionChanged event. I did find a way to work around it though, which may or may not be useful in your specific case. In my case I had a specific action that happened on rowSelectionChange that I wanted to prevent happening when the button was clicked. If that works for you here's how I'd do it.

Alter your cellTemplate to include a buttonClicked boolean:

cellTemplate: '<div><button ng-click="grid.appScope.buttonClicked = true;grid.appScope.genalert()">Click Here</button></div>'

Then in your rowSelectionChanged declaration:

gridApi.selection.on.rowSelectionChanged($scope, function (row) {
    if (!this.grid.appScope.buttonClicked) {
        alert(row.isSelected);
    }
    this.grid.appScope.buttonClicked = false;
});
Mordred
  • 3,734
  • 3
  • 36
  • 55