我有跟随ng-grid。
$scope.IssueGrid = {
data: 'IssueGridList',
multiSelect: false,
selectedItems: $scope.selectedRow,
enableColumnResize: true,
enableRowSelection: true,
headerRowHeight: 65,
columnDefs: [
{ field: 'Item', width: '25%', displayName: 'Item Name' },
{ field: 'RequiredQuantity', displayName: 'Requested Qty', cellTemplate: '<div style="text-align:right;" class="ngCellText">{{row.getProperty(col.field)}}</div>' },
{ field: '', width: '7%', displayName: 'To be Issued', cellTemplate: '<div class="ngCellText {{row.entity.cellClass}}"> <input type="text" id="issQty" style="text-align:right;" data-ng-change="editIssueQty(row)" data-ng-model="row.entity.IssueQty" number-only-input input-value = "row.entity.IssueQty" class="form-control" data-ng-disabled="issueQtyDisabled(row.entity)" value = {{row.getProperty(col.IssueQty)}} /></div>' },
],
showFooter: true
};
此网格有文本框输入&#34; IssueQty&#34;。但是当输入值时 发行数量,如果大于&#34; RequiredQuantity&#34;整行应突出显示。
任何人都可以建议一种方法来实现这一目标。
谢谢和问候。
答案 0 :(得分:2)
考虑使用rowTemplate
(请参阅Row Templates),使用ng-class
和row.getProperty
来设置“突出显示”&#39;整行的类。
rowTemplate:'<div ng-style="rowStyle(row)" ng-class="{highlighted: row.getProperty(\'IssueQty\') > row.getProperty(\'RequiredQuantity\') }"><div ng-style="{ \'cursor\': row.cursor }" ng-repeat="col in renderedColumns" ng-class="col.colIndex()" class="ngCell ">' +
'<div class="ngVerticalBar" ng-style="{height: rowHeight}" ng-class="{ ngVerticalBarVisible: !$last }"> </div>' +
'<div ng-cell></div>' +
'</div></div>'
(function() {
"use strict";
angular
.module("myApp", ['ngGrid'])
.controller("MyCtrl", ['$scope', MyCtrl]);
function MyCtrl($scope) {
$scope.IssueGridList = [
{Item:'test1', RequiredQuantity:1, IssueQty:0},
{Item:'test2', RequiredQuantity:2, IssueQty:0}
];
$scope.IssueGrid = {
data: 'IssueGridList',
multiSelect: false,
//selectedItems: $scope.selectedRow,
enableColumnResize: true,
enableRowSelection: true,
showFooter: true,
columnDefs: [
{ field: 'Item', width: '25%', displayName: 'Item Name' },
{ field: 'RequiredQuantity', width:'25%', displayName: 'Requested Qty', cellTemplate: '<div style="text-align:right;" class="ngCellText">{{row.getProperty(col.field)}}</div>' },
{ field: '', width: '50%', displayName: 'To be Issued', cellTemplate: '<div class="ngCellText {{row.entity.cellClass}}"> <input type="text" id="issQty" style="text-align:right;" data-ng-change="editIssueQty(row)" data-ng-model="row.entity.IssueQty" number-only-input input-value = "row.entity.IssueQty" class="form-control" data-ng-disabled="issueQtyDisabled(row.entity)" value = {{row.getProperty(col.IssueQty)}} /></div>' },
],
rowTemplate:'<div ng-style="rowStyle(row)" ng-class="{highlighted: row.getProperty(\'IssueQty\') > row.getProperty(\'RequiredQuantity\') }"><div ng-style="{ \'cursor\': row.cursor }" ng-repeat="col in renderedColumns" ng-class="col.colIndex()" class="ngCell ">' +
'<div class="ngVerticalBar" ng-style="{height: rowHeight}" ng-class="{ ngVerticalBarVisible: !$last }"> </div>' +
'<div ng-cell></div>' +
'</div></div>'
};
}
})();
&#13;
.gridStyle {
border: 1px solid rgb(212,212,212);
width: 500px;
height: 300px;
}
.highlighted {
background-color: yellow;
}
&#13;
<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/ng-grid/2.0.11/ng-grid.css" />
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/ng-grid/2.0.11/ng-grid.min.js"></script>
<div ng-app="myApp" ng-controller="MyCtrl">
<div class="gridStyle" ng-grid="IssueGrid"></div>
</div>
&#13;
答案 1 :(得分:1)
您可以在代码中尝试类似的内容 -
<input type="text" ng-style="{'background-color':'{{change}}'}" ng-change="anyFunction()">
在控制器中你可以写一个函数来改变那个特定文本框的css。喜欢 -
.controller('myApp',['$scope',function($scope){
$scope.change = /*any default value of color here*/
$scope.anyFunction = function{
/*if(required value greater than the demo quantity)
then change = /*your desired color*/;
*/
}
])