【发布时间】:2018-05-23 07:45:56
【问题描述】:
catsUser.controller('MainCtrl', ['$scope', '$http','uiGridConstants','$interval', function ($scope, $http,uiGridConstants,$interval) {
$scope.resultSummary=true;
$scope.getEventJson=function(){
$http.get('ui/app/components/cpf/user/data/JsonDataForGrid.json').then(function(response){
console.log(response)
$scope.EventList=response.data;
$scope.CreateGrids();
})
}
$scope.getEventJson();
$scope.data = {};
$scope.gridapis=[]
$scope.CreateGrids = function() {
var count=0;
angular.forEach($scope.EventList,function(Evt){
var eventData = "griddata" + count;
$scope.data[eventData] = [];
$scope.data[eventData] = {
enableRowSelection: false,
enableSorting: true,
enableColumnResizing: true,
enableGridMenu: true,
enableFiltering: false,
enableCellEditOnFocus:true,
multiSelect: true,
data:Evt.record,
columnDefs:Evt.col
};
count++;
$scope.data[eventData].onRegisterApi=function(gridApi){
console.log("ON REGISTER API FOR GRID:"+eventData);
var k=eventData.slice(-1);
$scope.gridapis[k]=gridApi
//Listener to change the color
gridApi.edit.on.afterCellEdit($scope,function(rowEntity,colDef,newval,oldval){
colDef.cellClass = function(grid, row, col, rowRenderIndex, colRenderIndex) {
if (rowEntity.EventID === row.entity.EventID &&newval !== oldval && row.isSelected==true) {
return "changecolor";
}
return "";
};
gridApi.core.notifyDataChange(uiGridConstants.dataChange.COLUMN);
})
if($scope.resultSummary){
$scope.gridapis[k].grid.modifyRows($scope.data['griddata'+k].data);
for(var i=0; i< $scope.selRows[k].length; i++){
if($scope.selRows[k])
gridApi.selection.selectRow(($scope.selRows[k])[i]);
}
}
}
})
};
$scope.selRows=[];
$scope.AllRowsData=[]
$scope.submitEvents=function(){
$scope.resultSummary=false;
angular.forEach($scope.gridapis,function(gridApi,key){
$scope.AllRowsData.push($scope.data['griddata'+key].data)
$scope.selRows[key]=gridApi.selection.getSelectedRows();
$scope.data['griddata'+key].enableRowHeaderSelection = false;
$scope.gridapis[key].core.notifyDataChange( uiGridConstants.dataChange.OPTIONS);
$scope.data['griddata'+key].data=$scope.selRows[key];
})
}
$scope.backToResultSummary=function(){
$scope.resultSummary=true;
angular.forEach($scope.gridapis,function(gridApi,key){
$scope.data['griddata'+key].data=$scope.AllRowsData[key];
$scope.data['griddata'+key].enableRowHeaderSelection = true;
gridApi.core.notifyDataChange( uiGridConstants.dataChange.OPTIONS);
})
}
$scope.isActive=function(){
return true
}
$scope.toggleAccord=function(){
if($scope.isActive==true){
$scope.isActive=false
}
if($scope.isActive==false){
$scope.isActive=true
}
}
}]);
//JSON DATA
[
{
"EventName": "BONU CA00007986795 / 0031366-000 / Euroclear 96008",
"col": [
{
"name": "EventID",
"displayName": "EventID"
},
{
"name": "Account ID",
"displayName": "Account ID"
},
{
"name": "Reference No",
"displayName": "Reference No"
},
{
"name": "Security",
"displayName": "Security"
},
{
"name": "Event Type",
"displayName": "Event Type"
},
{
"name": "Event Category",
"displayName": "Event Category"
},
{
"name": "Ex Date",
"displayName": "Ex Date"
},
{
"name": "Entitlement Method",
"displayName": "Entitlement Method"
},
{
"name": "Rate",
"displayName": "Rate"
},
{
"name": "Rate Per share",
"displayName": "Rate Per share"
},
{
"name": "Type",
"displayName": "Type"
},
{
"name": "Status",
"displayName": "Status"
},
{
"name": "Source",
"displayName": "Source"
}
],
"record": [
{
"EventID": "CA00007986795",
"Account ID": "NBL0178529",
"Reference No": "US0378331005",
"Security": "APPLE INC",
"Event Type": "BONU",
"Event Category": "MAND",
"Ex Date": "15/10/2017",
"Entitlement Method": "Calculated/NV",
"Rate": "1751",
"Rate Per share": " ",
"Type": "NEWM",
"Status": "Released",
"Source": "EUROCLEAR"
},
{
"EventID": "CA00007986796",
"Account ID": "NBL0178529",
"Reference No": "US0378331005",
"Security": "APPLE INC",
"Event Type": "BONU",
"Event Category": "MAND",
"Ex Date": "15/10/2017",
"Entitlement Method": "Calculated/NV",
"Rate": "2751",
"Rate Per share": " ",
"Type": "NEWM",
"Status": "Released",
"Source": "EUROCLEAR"
},
{
"EventID": "CA00007986797",
"Account ID": "NBL0178529",
"Reference No": "US0378331005",
"Security": "APPLE INC",
"Event Type": "BONU",
"Event Category": "MAND",
"Ex Date": "15/10/2017",
"Entitlement Method": "Calculated/NV",
"Rate": "2751",
"Rate Per share": "275/109.31 USD",
"Type": "NEWM",
"Status": "Released",
"Source": "EUROCLEAR"
}
]
},
{
"EventName": "BONU CA00007986795 / 0022255-001 / Euroclear 96008",
"col": [
{
"name": "EventID",
"displayName": "EventID"
},
{
"name": "Account ID",
"displayName": "Account ID"
},
{
"name": "Reference No",
"displayName": "Reference No"
},
{
"name": "Security",
"displayName": "Security"
},
{
"name": "Event Type",
"displayName": "Event Type"
},
{
"name": "Event Category",
"displayName": "Event Category"
},
{
"name": "Ex Date",
"displayName": "Ex Date"
},
{
"name": "Entitlement Method",
"displayName": "Entitlement Method"
},
{
"name": "Rate",
"displayName": "Rate"
},
{
"name": "Rate Per share",
"displayName": "Rate Per share"
},
{
"name": "Type",
"displayName": "Type"
},
{
"name": "Status",
"displayName": "Status"
},
{
"name": "Source",
"displayName": "Source"
}
],
"record": [
{
"EventID": "CA00007986795",
"Account ID": "NBL0178529",
"Reference No": "US0378331005",
"Security": "APPLE INC",
"Event Type": "BONU",
"Event Category": "MAND",
"Ex Date": "15/10/2017",
"Entitlement Method": "Calculated/NV",
"Rate": "1751",
"Rate Per share": " ",
"Type": "NEWM",
"Status": "Released",
"Source": "EUROCLEAR"
},
{
"EventID": "CA00007986796",
"Account ID": "NBL0178529",
"Reference No": "US0378331005",
"Security": "APPLE INC",
"Event Type": "BONU",
"Event Category": "MAND",
"Ex Date": "15/10/2017",
"Entitlement Method": "Calculated/NV",
"Rate": "2751",
"Rate Per share": " ",
"Type": "REPE",
"Status": "Released",
"Source": "EUROCLEAR"
},
{
"EventID": "CA00007986797",
"Account ID": "NBL0178529",
"Reference No": "US0378331005",
"Security": "APPLE INC",
"Event Type": "BONU",
"Event Category": "MAND",
"Ex Date": "15/10/2017",
"Entitlement Method": "Calculated/NV",
"Rate": "2751",
"Rate Per share": "275/109.31 USD",
"Type": "REPE",
"Status": "Released",
"Source": "EUROCLEAR"
}
]
},
{
"EventName": "BONU CA00007986795 / 0045386-000 / Euroclear 96008",
"col": [
{
"name": "EventID",
"displayName": "EventID"
},
{
"name": "Account ID",
"displayName": "Account ID"
},
{
"name": "Reference No",
"displayName": "Reference No"
},
{
"name": "Security",
"displayName": "Security"
},
{
"name": "Event Type",
"displayName": "Event Type"
},
{
"name": "Event Category",
"displayName": "Event Category"
},
{
"name": "Ex Date",
"displayName": "Ex Date"
},
{
"name": "Entitlement Method",
"displayName": "Entitlement Method"
},
{
"name": "Rate",
"displayName": "Rate"
},
{
"name": "Rate Per share",
"displayName": "Rate Per share"
},
{
"name": "Type",
"displayName": "Type"
},
{
"name": "Status",
"displayName": "Status"
},
{
"name": "Source",
"displayName": "Source"
}
],
"record": [
{
"EventID": "CA00007986795",
"Account ID": "NBL0178529",
"Reference No": "US0378331005",
"Security": "APPLE INC",
"Event Type": "BONU",
"Event Category": "MAND",
"Ex Date": "15/10/2017",
"Entitlement Method": "Calculated/NV",
"Rate": "1751",
"Rate Per share": " ",
"Type": "NEWM",
"Status": "Released",
"Source": "EUROCLEAR"
},
{
"EventID": "CA00007986796",
"Account ID": "NBL0178529",
"Reference No": "US0378331005",
"Security": "APPLE INC",
"Event Type": "BONU",
"Event Category": "MAND",
"Ex Date": "15/10/2017",
"Entitlement Method": "Calculated/NV",
"Rate": "2751",
"Rate Per share": " ",
"Type": "NEWM",
"Status": "Released",
"Source": "EUROCLEAR"
},
{
"EventID": "CA00007986797",
"Account ID": "NBL0178529",
"Reference No": "US0378331005",
"Security": "APPLE INC",
"Event Type": "BONU",
"Event Category": "MAND",
"Ex Date": "15/10/2017",
"Entitlement Method": "Calculated/NV",
"Rate": "2751",
"Rate Per share": "275/109.31 USD",
"Type": "NEWM",
"Status": "Released",
"Source": "EUROCLEAR"
}
]
},
{
"EventName": "BONU CA00007986795 / 0019555-000 / Mitsubishi 87x564",
"col": [
{
"name": "EventID",
"displayName": "EventID"
},
{
"name": "Account ID",
"displayName": "Account ID"
},
{
"name": "Reference No",
"displayName": "Reference No"
},
{
"name": "Security",
"displayName": "Security"
},
{
"name": "Event Category",
"displayName": "Event Category"
},
{
"name": "Status",
"displayName": "Status"
},
{
"name": "Source",
"displayName": "Source"
}
],
"record": [
{
"EventID": "CA00007986795",
"Account ID": "NBL0178529",
"Reference No": "US0378331005",
"Security": "DEVON ENERGY",
"Event Category": "MAND",
"Status": "Released",
"Source": "Mitsubishi"
},
{
"EventID": "CA00007986796",
"Account ID": "NBL0178529",
"Reference No": "US0378331005",
"Security": "DEVON ENERGY",
"Event Category": "MAND",
"Status": "Released",
"Source": "Mitsubishi"
}
]
},
{
"EventName": "INTR CA00007986777 / 0045390-000 / BNP Parib. Mill. 100960-208",
"col": [
{
"name": "EventID",
"displayName": "EventID"
},
{
"name": "Account ID",
"displayName": "Account ID"
},
{
"name": "Reference No",
"displayName": "Reference No"
},
{
"name": "Security",
"displayName": "Security"
},
{
"name": "Event Type",
"displayName": "Event Type"
},
{
"name": "Event Category",
"displayName": "Event Category"
},
{
"name": "Ex Date",
"displayName": "Ex Date"
},
{
"name": "Entitlement Method",
"displayName": "Entitlement Method"
},
{
"name": "Amount",
"displayName": "Amount"
},
{
"name": "Balance",
"displayName": "Balance"
},
{
"name": "Type",
"displayName": "Type"
},
{
"name": "Status",
"displayName": "Status"
},
{
"name": "Source",
"displayName": "Source"
}
],
"record": [
{
"EventID": "CA00007986777",
"Account ID": "NBL0178529",
"Reference No": "US0378331005",
"Security": "APPLE INC",
"Event Type": "INTR",
"Event Category": "MAND",
"Ex Date": "15/10/2017",
"Entitlement Method": "Calculated",
"Amount": "10000",
"Balance": "1000 /-",
"Type": "NEWM",
"Status": "Released",
"Source": "BNP Parib. Mill."
}
]
},
{
"EventName": "INTR CA00007986777 / 0045500-000 / BNP Parib. Mill. 325043-450",
"col": [
{
"name": "EventID",
"displayName": "EventID"
},
{
"name": "Account ID",
"displayName": "Account ID"
},
{
"name": "Reference No",
"displayName": "Reference No"
},
{
"name": "Security",
"displayName": "Security"
}
],
"record": [
{
"EventID": "CA00007986777",
"Account ID": "NBL0178529",
"Reference No": "US0378331005",
"Security": "APPLE INC"
},
{
"EventID": "CA00007986778",
"Account ID": "NBL0178529",
"Reference No": "US0378331005",
"Security": "APPLE INC"
}
]
},
{
"EventName": "INTR CA00007986777 / 0055555-000 / BNP Parib. Mill. 104444-477",
"col": [
{
"name": "EventID",
"displayName": "EventID"
},
{
"name": "Account ID",
"displayName": "Account ID"
},
{
"name": "Reference No",
"displayName": "Reference No"
},
{
"name": "Security",
"displayName": "Security"
},
{
"name": "Event Type",
"displayName": "Event Type"
},
{
"name": "Event Category",
"displayName": "Event Category"
},
{
"name": "Ex Date",
"displayName": "Ex Date"
},
{
"name": "Entitlement Method",
"displayName": "Entitlement Method"
},
{
"name": "Amount",
"displayName": "Amount"
},
{
"name": "Balance",
"displayName": "Balance"
},
{
"name": "Type",
"displayName": "Type"
},
{
"name": "Status",
"displayName": "Status"
},
{
"name": "Source",
"displayName": "Source"
}
],
"record": [
{
"EventID": "CA00007986795",
"Account ID": "NBL0178529",
"Reference No": "US0378331005",
"Security": "APPLE INC",
"Event Type": "BONU",
"Event Category": "MAND",
"Ex Date": "15/10/2017",
"Entitlement Method": "Calculated",
"Amount": "10000",
"Balance": "397.50 USD",
"Type": "REPE",
"Status": "Released",
"Source": "BNP Parib. Mill."
},
{
"EventID": "CA00007986796",
"Account ID": "NBL0178529",
"Reference No": "US0378331005",
"Security": "APPLE INC",
"Event Type": "BONU",
"Event Category": "MAND",
"Ex Date": "15/10/2017",
"Entitlement Method": "Calculated",
"Amount": "10000",
"Balance": "397.50 USD",
"Type": "NEWM",
"Status": "Released",
"Source": "BNP Parib. Mill."
}
]
}
]
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<input ng-if="resultSummary" type="button" value="Submit" ng-click="submitEvents()">
<input ng-if="!resultSummary" type="button" value="Back" ng-click="backToResultSummary()">
<accordion close-others="false">
<accordion-group is-open="isActive" ng-click="toggleAccord()" ng-repeat="obj in data" ng-if="data['griddata'+$index].data.length>0">
<accordion-heading>
{{EventList[$index].EventName}}
</accordion-heading>
<div ng-if="resultSummary" class="grid" style="width:1570px;background-color:white;" ui-grid-edit ui-grid-move-columns ui-grid="data['griddata'+$index]"
ui-grid-selection>
</div>
<div ng-if="!resultSummary" class="grid" style="width:1570px;background-color:white;" ui-grid-edit ui-grid-move-columns ui-grid="data['griddata'+$index]"
>
</div>
</accordion-group>
</accordion>
我有两个 ui 网格。在第一个 Ui 网格中,我有一个 afteredit 侦听器,如果编辑单元格,它会通过 columndef cellclass 更改单元格的颜色。
假设我在网格中编辑了几个单元格并且单元格的颜色发生了变化。
现在我想显示第一个网格的行以及更改后的颜色...我能够显示这些行但我无法更改第二个单元格类,因为我不知道从哪里开始。
注意:-im 使用动态的多个 ui 网格。 Columndef 是动态给定的。所以我不能在 columndef 中编写单元类。我们必须以编程方式设置它
【问题讨论】:
-
您能否发布您的代码的最低工作示例 (MWE),以便人们可以清楚地看到您在问什么?
标签: javascript html angularjs node.js angularjs-scope