3

I am using ui-Grid v 3.0.1.

I have a custom cell template for a particular column which displays a button in each row. I have attached a ng-click attribute which calls the appScope to trigger some action.

All works beautifully.

However, the clicking of the custom template button also causes the selection of the row in question to be toggled.

I need to prevent this from happening.

i.e. a click to the custom template button should leave the current row's selection status as it was.

I suspect I need to cancel the row selection event somehow.

Can anyone point me in the right direction?

vm.gridOptions = {
        data: "vm.myGridData",
        columnDefs: [
            { field: "Col1", displayName: "Col1", width: 100 },
            { field: "Col2", displayName: "Col2", width: 200 },
            { name: " ", cellTemplate: "<div><button ng-click='grid.appScope.displayRecord(row.entity)'><i class='fa fa-search'></i></button></div>" }
        ],
        enableRowSelection: true,
        enableSelectAll: true,
        showGridFooter: true,
        multiSelect: true,
        enableSorting: true,
        enableFiltering: true,
        enableFullRowSelection: true,
        enableRowHeaderSelection: true
    };
Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
user2209634
  • 529
  • 7
  • 27
  • Possible duplicate of [ng-grid/ui-grid celltemplate on click causes row to be selected.](http://stackoverflow.com/questions/26471978/ng-grid-ui-grid-celltemplate-on-click-causes-row-to-be-selected) – Robert Cutajar Apr 12 '16 at 17:50

1 Answers1

5

Just add

$event.stopPropagation();

to the ng-click attribute as you can see in this plunker.

You can chain javascript calls inside your ng-click attribute just by writing them one next to another with a ; as a separator like this:

ng-click = "instructionOne(); instructionTwo(argument); $event.stopPropagation();"
imbalind
  • 1,182
  • 6
  • 13
  • Credits go to this answer wich is not related to the grid: http://stackoverflow.com/a/20301030/2453383 – imbalind Dec 14 '15 at 09:51