javascript 向 ng-grid 行添加一个类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19667709/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Add a class to ng-grid row
提问by robert.bo.roth
I'm using ng-grid to display a collection of files that are being uploaded (each file has its own row).
我正在使用 ng-grid 显示正在上传的文件集合(每个文件都有自己的行)。
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?
我将如何将一个类添加到整行?
回答by pmoule
You have to use a row template. In this template you can use ng-class
and dynamically assign a CSS class by databinding.
您必须使用行模板。在此模板中,您可以ng-class
通过数据绑定使用和动态分配 CSS 类。
A simple example:
一个简单的例子:
HTML
HTML
<body ng-controller="MyCtrl">
<div class="grid" ng-grid="gridOptions"></div>
</body>
JavaScript
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
CSS
.grid {
width: 300px;
height: 100px;
border: solid 1px rgb(90,90,90);
}
.red {
background-color: red;
color: white;
}
回答by robert.bo.roth
I'm dumb. There's a standard configuration option for this, namely, rowTemplate
.
我很笨 为此有一个标准配置选项,即rowTemplate
.
Thanks to @charlieftl for making me re-read the docs :)
感谢@charlieftl 让我重新阅读文档:)