需要在ui-grid中获取分组值

时间:2016-06-10 12:28:24

标签: angularjs angular-ui-grid ui-grid

我正在使用ui-grid并且我正在对数据进行分组,我需要获取组头和计数器。我怎样才能获得这些价值观?

这是网格的示例

enter image description here

$scope.gridOptions = {
        enableFiltering: false,
        enableColumnResize: true,
        onRegisterApi: function (gridApi) {
            $scope.gridApi = gridApi;
        },        
        columnDefs: [
          { field: 'month',enableHiding: false, grouping: { groupPriority: 0 }, sort: { priority: 0, direction: 'desc' }},
          { field: 'facility',enableHiding: false,grouping: { groupPriority: 1 }, sort: { priority: 1, direction: 'asc' }}, 
         ...  
          { field: 'categorymanager',enableHiding: false, displayName:'CM', grouping:{ groupPriority: 2 }, sort: { priority: 2, direction: 'asc' }},
       ]
   };

1 个答案:

答案 0 :(得分:0)

您可以为cellTemplate编写自定义colDef来获取值。例如,如果您可以将模板定义为:

let monthTemplate = '<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">{{grid.appScope.getValue(COL_FIELD, row.treeNode.children )}}</div></div>';

然后将您的方法定义为:

$scope.getValue = function(item, treeRowEntity){
      //item will hold month value
      //iterate over treerowentity array and get values
      //for example, if column required was facility
      treeRowEntity[0].row.entity.facility
    };