1
votes

I use angular ui-grid to display my data.

I enabled the option to select row in gridOptions:

enableRowSelection: true,

But for specific rows I disable the selection by this code:

$scope.mygrid.isRowSelectable = function (row) {
    if (row.entity.id == 2) {
        return false;
    } else {
        return true;
    }
};

This is work, I cant select row with id =2,

But I want to add class for this row to notify that it is unselectable.

Any idea?

2

2 Answers

1
votes

To Highlight the actual row:

You can write your own rowTemplate and assign the class to the row based on the entity id something like this,

 var rowTemplate =  '<div>' +
                 '  <div ng-class="{ \'red\': row.entity.company==\'Enersol\' }" ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.colDef.name" class="ui-grid-cell" ng-class="{ \'ui-grid-row-header-cell\': col.isRowHeader }"  ui-grid-cell></div>' +
                 '</div>';
  $scope.gridOptions = {
    rowTemplate:rowTemplate,
    enableSorting: true,
    columnDefs: [
      { field: 'name'},
      { field: 'company'}
    ]
  };

Instead of the row.entity.company=\'Enersol\' you can change it to row.entity.id and assign the class name.

In this example the the 'red' gives background color of yellow and foreground color of red.

Take a look at this plnkr. http://plnkr.co/edit/vaqBY235Lfz7WLvy0FCc?p=preview

To modify the actual row header icons:

You can override the template for the selection row header buttons and add custom class css. Inject templateCache in your controller and override the template like this.

$templateCache.put('ui-grid/selectionRowHeaderButtons',
    "<div class=\"ui-grid-selection-row-header-buttons\" ng-class=\"{'ui-grid-row-selected': row.isSelected , 'ui-grid-icon-cancel':!grid.appScope.isSelectable(row.entity), 'ui-grid-icon-ok':grid.appScope.isSelectable(row.entity)}\" ng-click=\"selectButtonClick(row, $event)\">&nbsp;</div>"
  );

The template uses a method in your controller scope to identify whether the row is selectable.

Sample plnkr here http://plnkr.co/edit/vaqBY235Lfz7WLvy0FCc?p=preview

0
votes

In the columnDefs you can add a cellClass.

function applyClass(grid, row, col, rowRenderIndex, colRenderIndex) {
    if (row.entity.IsMapped) {
        return 'disabledRow';
    }
}

$scope.yourGrid = {
    columnDefs: [
        { cellClass: applyClass }
    ]
};