最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Add a class to ng-grid row - Stack Overflow

programmeradmin7浏览0评论

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?

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?

Share Improve this question asked Oct 29, 2013 at 19:43 robert.bo.rothrobert.bo.roth 1,3534 gold badges15 silver badges24 bronze badges 2
  • 2 can set your own templates... then in template set ng-class based onwhatever variable you need to momitor. See docs for link to github wiki regarding templates – charlietfl Commented Oct 29, 2013 at 20:36
  • Ah, thanks mate. I was looking through the docs for like 30 minutes, I'm not sure how i missed the rowTemplate config option. – robert.bo.roth Commented Oct 29, 2013 at 20:42
Add a ment  | 

2 Answers 2

Reset to default 13

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

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

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

发布评论

评论列表(0)

  1. 暂无评论