Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a class to ng-grid row

I'm using ng-grid to display a collection of files that are being uploaded (each file has its own row).

If one/any of the files fails to upload, I'd like to modify that row and put a class on it to show that it failed to upload.

How would I go about adding a class to an entire row?

like image 852
robert.bo.roth Avatar asked Oct 29 '13 19:10

robert.bo.roth


2 Answers

You have to use a row template. In this template you can use ng-class and dynamically assign a CSS class by databinding.

A simple example:

HTML

<body ng-controller="MyCtrl">
    <div class="grid" ng-grid="gridOptions"></div>
</body>

JavaScript

var app = angular.module('myApp', ['ngGrid']);

app.controller('MyCtrl', function($scope) {
  $scope.fileOneUploaded = true;
  $scope.fileTwoUploaded = false;

  $scope.gridData = [{fileName: 'File 1', size: 1000, isUploaded: $scope.fileOneUploaded },
                {fileName: 'File 2', size: 2000, isUploaded: $scope.fileTwoUploaded }];
  $scope.gridOptions = { 
    data: 'gridData',
    rowTemplate: '<div style="height: 100%" ng-class="{red: !row.getProperty(\'isUploaded\')}">' + 
                    '<div ng-repeat="col in renderedColumns" ng-class="col.colIndex()" class="ngCell ">' +
                      '<div ng-cell></div>' +
                    '</div>' +
                 '</div>'

  }
});

CSS

.grid {
  width: 300px; 
  height: 100px;
  border: solid 1px rgb(90,90,90);
}

.red {
  background-color: red;
  color: white;
}
like image 52
pmoule Avatar answered Oct 05 '22 20:10

pmoule


I'm dumb. There's a standard configuration option for this, namely, rowTemplate.

Thanks to @charlieftl for making me re-read the docs :)

like image 37
robert.bo.roth Avatar answered Oct 05 '22 19:10

robert.bo.roth