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

流过昼夜 提交于 2019-12-25 08:26:50

问题


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


回答1:


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)
       }
  }; 


来源:https://stackoverflow.com/questions/39244455/how-to-highlight-the-current-row-when-cell-template-button-is-clicked-in-anguala

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!