gihan-maduranga
gihan-maduranga

Reputation: 4811

How to highlight the current row when cell template button is clicked in angualar UI Grid

I have enabled ui-grid-selection on grid.As a result that when row is selected it will be get highlighted but my requirement is that i want to highlight the row only when the cell template button is clicked.Please let me know how to do this.

Code Sample

Upvotes: 0

Views: 549

Answers (1)

gihan-maduranga
gihan-maduranga

Reputation: 4811

Finally was able to find a way to do that.Here is the answer.

What i did was,

  1. In grid option changed enableRowSelection: false.
  2. Add a function to cell template button.

Button Cell Template

<div><button class="btn btn-default" ng-click="grid.appScope.selectRow(row)">O</button></div>
  1. Implement a function to select given row obj.

    $scope.selectRow = function(row) { row.setSelected(true); };

if you want to unselect the selected row when the template button is clicked again you can use row.isSelectedthis will return boolean value.Here is the updated function code snippet.

$scope.selectRow = function(row) {
       if(row.isSelected!=true){
         //Select the row
         row.setSelected(true)
       }else{
          row.setSelected(false)
       }
  }; 

Upvotes: 1

Related Questions