Javascript 角度UI网格条件着色选择
我想根据网格中的数据应用条件着色。 为此,我使用columnDefs中的cellClass函数。 我的问题是,这些类不会在选择更改时更新,并且我无法为选定的行定义颜色,这些行也具有条件着色。 因此,对于ex,一些行根据数据被涂成红色,当它们被选中时,它们的颜色应该是深红色,以显示选择和条件 有没有办法做到这一点 这就是我试图做的,但显然它不起作用,因为在选择更改时未调用此函数:Javascript 角度UI网格条件着色选择,javascript,angularjs,ui-grid,Javascript,Angularjs,Ui Grid,我想根据网格中的数据应用条件着色。 为此,我使用columnDefs中的cellClass函数。 我的问题是,这些类不会在选择更改时更新,并且我无法为选定的行定义颜色,这些行也具有条件着色。 因此,对于ex,一些行根据数据被涂成红色,当它们被选中时,它们的颜色应该是深红色,以显示选择和条件 有没有办法做到这一点 这就是我试图做的,但显然它不起作用,因为在选择更改时未调用此函数: vm.getCellHighlight = function(grid, row, col, rowRende
vm.getCellHighlight = function(grid, row, col, rowRenderIndex, colRenderIndex) {
var rowStatus = row.entity.isChild ? grid.parentRow.entity.transactionItemStatus : row.entity.transactionItemStatus;
var rowSelected = row.isSelected ? 'Selected' : '';
var rowType = '';
if (rowStatus == ticketStateStorno){
rowType = 'Storno';
}
if (rowStatus == ticketStateUsed){
rowType = 'Used';
}
return (rowRenderIndex % 2)? 'searchSalesGridHighlight' + rowType + 'Dark' + rowSelected : 'searchSalesGridHighlight' + rowType + 'Light' + rowSelected;
};
我相信这可能接近你想要的,按位计算 JavaScript/AngularJS控制器:
app.controller('MainCtrl', ['$scope', '$http', function($scope, $http) {
var colorRowTemplate =
//same as normal template, but extra ng-class for old people: 'old-people':(row.entity.Age>25&&!row.isSelected), 'old-people-selected':(row.entity.Age>25&&row.isSelected)
"<div ng-repeat=\"(colRenderIndex, col) in colContainer.renderedColumns track by col.uid\" ui-grid-one-bind-id-grid=\"rowRenderIndex + '-' + col.uid + '-cell'\" class=\"ui-grid-cell\" ng-class=\"{'old-people':(row.entity.Age>25&&!row.isSelected), 'old-people-selected':(row.entity.Age>25&&row.isSelected), 'ui-grid-row-header-cell': col.isRowHeader }\" role=\"{{col.isRowHeader ? 'rowheader' : 'gridcell'}}\" ui-grid-cell></div>";
$scope.gridOptions = {
enableSelectAll: true,
enableRowSelection: true,
enableRowHeaderSelection: false,
enableFullRowSelection: true,
rowTemplate: colorRowTemplate,
showGridFooter: true
}
$http.get('data.json')
.then(function(response) {
$scope.gridOptions.data = response.data;
});
}]);
app.controller('MainCtrl',['$scope','$http',函数($scope,$http){
变量colorRowTemplate=
//与普通模板相同,但为老年人增加了ng类:“old people”:(row.entity.Age>25&&!row.isSelected),“old people selected”:(row.entity.Age>25&&row.isSelected)
"";
$scope.gridOptions={
enableSelectAll:true,
enableRowSelection:true,
enableRowHeaderSelection:false,
enableFullRowSelection:true,
rowTemplate:colorRowTemplate,
showGridFooter:true
}
$http.get('data.json')
.然后(功能(响应){
$scope.gridOptions.data=response.data;
});
}]);
这是一个可以工作的打捞器。谢谢蒂姆,不仅离我很近,而且正是我所需要的!