Angularjs ng-grid 动态高亮行
Angularjs ng-grid Highlight row dynamically
我有以下 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
};
此网格有可输入的文本框 "IssueQty"。但是当输入值时
已发行数量,如果大于 "RequiredQuantity" 整行应突出显示。
任何人都可以提出实现此目标的方法..
感谢和问候。
你可以在你的代码中尝试这样的事情 -
<input type="text" ng-style="{'background-color':'{{change}}'}" ng-change="anyFunction()">
并且在控制器中,您可以编写一个函数来更改特定 textbox.Like -
的 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*/;
*/
}
])
考虑使用 rowTemplate
(参见 Row Templates),它使用 ng-class
和 row.getProperty
为整个设置 'highlight' class行。
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>'
};
}
})();
.gridStyle {
border: 1px solid rgb(212,212,212);
width: 500px;
height: 300px;
}
.highlighted {
background-color: yellow;
}
<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>
我有以下 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
};
此网格有可输入的文本框 "IssueQty"。但是当输入值时 已发行数量,如果大于 "RequiredQuantity" 整行应突出显示。
任何人都可以提出实现此目标的方法..
感谢和问候。
你可以在你的代码中尝试这样的事情 -
<input type="text" ng-style="{'background-color':'{{change}}'}" ng-change="anyFunction()">
并且在控制器中,您可以编写一个函数来更改特定 textbox.Like -
的 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*/;
*/
}
])
考虑使用 rowTemplate
(参见 Row Templates),它使用 ng-class
和 row.getProperty
为整个设置 'highlight' class行。
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>'
};
}
})();
.gridStyle {
border: 1px solid rgb(212,212,212);
width: 500px;
height: 300px;
}
.highlighted {
background-color: yellow;
}
<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>