Angular ui-网格分组显示重复行
Angular ui-grid grouping showing duplicate rows
我是 Angular 的新手,正在尝试使用 Angular ui.grid.grouping 对行进行分组。但是我看到重复的行并且没有正确分组。我正在使用 Angular js 1.7.2 版本
app.js
var app = angular.module('app', ['ngAnimate', 'ngTouch', 'ui.grid', 'ui.grid.grouping' ]);
app.controller('MainCtrl', ['$scope', '$http', '$interval', 'uiGridGroupingConstants', function ($scope, $http, $interval, uiGridGroupingConstants ) {
$scope.gridOptions = {
enableSorting: true,
enableGrouping:true,
treeRowHeaderAlwaysVisible: false,
columnDefs: [
{ name: 'City', width:'50%', grouping: { groupPriority: 0 },defaultSort: {priority: 0}},
{ name: 'CustomerName', width:'30%' }
],
onRegisterApi: function( gridApi ) {
$scope.gridApi = gridApi;
}
};
$scope.gridOptions.data = [
{ "City": "TEXAS", "CustomerName": "AAA"},
{ "City": "TEXAS", "CustomerName": "BBB"},
{ "City": "TEXAS", "CustomerName": "CCC" },
{ "City": "MICHIGAN", "CustomerName": "DDD" },
{ "City": "NEW YORK","CustomerName": "EEE" },
{ "City": "MICHIGAN" ,"CustomerName": "FFF"},
{ "City": "MICHIGAN", "CustomerName": "GGG" },
{ "City": "MICHIGAN", "CustomerName": "HHH" },
{ "City": "NEW YORK","CustomerName": "III" }
];
}])
HTML:
<div ng-controller="MainCtrl">
<div id="grid1" ui-grid="gridOptions" ui-grid-grouping class="grid"></div>
</div>
实际结果:
预期结果:
- 而不是 2 密歇根 1 密歇根
- 而不是 2 纽约 1 纽约
使用 ng-grid 尝试了同样的事情,我得到了与 below:Exactly 相同的结果,我正在尝试使用 angular ui-网格
@Steve,感谢您的建议。根据您的建议,我在注册 Api 时添加了延迟分组,如下所示:
onRegisterApi: function( gridApi ) {
$scope.gridApi = gridApi;
$timeout(function(){
$scope.gridApi.grouping.clearGrouping();
$scope.gridApi.grouping.groupColumn('City');
}, 300);
}
它修复了它。
尝试为这一行添加列,它对我有帮助:
sort: { priority: 0, direction: 'asc' }
我是 Angular 的新手,正在尝试使用 Angular ui.grid.grouping 对行进行分组。但是我看到重复的行并且没有正确分组。我正在使用 Angular js 1.7.2 版本
app.js
var app = angular.module('app', ['ngAnimate', 'ngTouch', 'ui.grid', 'ui.grid.grouping' ]);
app.controller('MainCtrl', ['$scope', '$http', '$interval', 'uiGridGroupingConstants', function ($scope, $http, $interval, uiGridGroupingConstants ) {
$scope.gridOptions = {
enableSorting: true,
enableGrouping:true,
treeRowHeaderAlwaysVisible: false,
columnDefs: [
{ name: 'City', width:'50%', grouping: { groupPriority: 0 },defaultSort: {priority: 0}},
{ name: 'CustomerName', width:'30%' }
],
onRegisterApi: function( gridApi ) {
$scope.gridApi = gridApi;
}
};
$scope.gridOptions.data = [
{ "City": "TEXAS", "CustomerName": "AAA"},
{ "City": "TEXAS", "CustomerName": "BBB"},
{ "City": "TEXAS", "CustomerName": "CCC" },
{ "City": "MICHIGAN", "CustomerName": "DDD" },
{ "City": "NEW YORK","CustomerName": "EEE" },
{ "City": "MICHIGAN" ,"CustomerName": "FFF"},
{ "City": "MICHIGAN", "CustomerName": "GGG" },
{ "City": "MICHIGAN", "CustomerName": "HHH" },
{ "City": "NEW YORK","CustomerName": "III" }
];
}])
HTML:
<div ng-controller="MainCtrl">
<div id="grid1" ui-grid="gridOptions" ui-grid-grouping class="grid"></div>
</div>
实际结果:
预期结果:
- 而不是 2 密歇根 1 密歇根
- 而不是 2 纽约 1 纽约
使用 ng-grid 尝试了同样的事情,我得到了与 below:Exactly 相同的结果,我正在尝试使用 angular ui-网格
@Steve,感谢您的建议。根据您的建议,我在注册 Api 时添加了延迟分组,如下所示:
onRegisterApi: function( gridApi ) {
$scope.gridApi = gridApi;
$timeout(function(){
$scope.gridApi.grouping.clearGrouping();
$scope.gridApi.grouping.groupColumn('City');
}, 300);
}
它修复了它。
尝试为这一行添加列,它对我有帮助:
sort: { priority: 0, direction: 'asc' }