我在ui-grid中使用分组功能,但是我想通过taskId而不是taskName进行分组,因为taskNames在我的项目中不是唯一的。所以我这样做了,
$scope.gridOptions.columnDefs = [
{
field:'taskId',
displayName:'Task Name',
cellTemplate:'<span>{{row.entity.taskName}}</span>'
grouping:{
groupingPriority:0
}
}
.....
]
其中网格按taskId分组,但taskName用于表示。 但是这不能正确地呈现为组顶部的标题行。但适合儿童群体。有人遇到过这个问题吗?
答案 0 :(得分:2)
组顶级没有行,因为可能有许多子行分组在一个组下。所以row.entity实际上是一个具有组级别值的对象。您可以遍历组子项,然后使用其中一个子组来呈现组标题。
你可以尝试这方面的事情,
$scope.gridOptions = {
//enableFiltering: true,
treeRowHeaderAlwaysVisible: false,
columnDefs: [
{ name: 'name', width: '30%' },
{ name: 'gender', grouping: { groupPriority: 1 }, sort: { priority: 1, direction: 'asc' }, width: '20%', cellFilter: 'mapGender' },
{ name: 'age', treeAggregationType: uiGridGroupingConstants.aggregation.MAX, width: '20%' },
{ name: 'company', width: '25%' },
{ name: 'registered', width: '40%', cellFilter: 'date', type: 'date' },
{ name: 'zip', displayName:'State' ,grouping: { groupPriority: 0 }, sort: { priority: 0, direction: 'desc' }, width: '35%', cellTemplate: '<span>{{grid.appScope.name(grid, row)}}</span>' },
//the below commented is the actual col but I did grouping with zip and put state of that zip
//{ name: 'state', grouping: { groupPriority: 0 }, sort: { priority: 0, direction: 'desc' }, width: '35%', cellTemplate: '<div><div ng-if="!col.grouping || col.grouping.groupPriority === undefined || col.grouping.groupPriority === null || ( row.groupHeader && col.grouping.groupPriority === row.treeLevel )" class="ui-grid-cell-contents" title="TOOLTIP">{{COL_FIELD CUSTOM_FILTERS}}</div></div>' },
],
};
$scope.name = function(grid,row,col)
{
console.log(row);
if(row.groupHeader && row.treeNode.children[0].row.treeNode.children[0])
{
var entity = row.treeNode.children[0].row.treeNode.children[0].row.entity;
return entity.state;
}
else if(row.treeNode.children[0])
{
var entity = row.treeNode.children[0].row.entity;
return entity.state;
}
return row.entity.state;
}