简体   繁体   English

对象的角度ui网格分组

[英]angular ui-grid grouping from object

I am using ui-grid v3.0.0-rc.22 in my application. 我在我的应用程序中使用ui-grid v3.0.0-rc.22。

I use grouping in my grid. 我在网格中使用分组。 I have data as follow 我的数据如下

[{
            "_id": "559dfaa671c2bd2c0a00002f",
            "title": "dfds",
            "sku": "fdsf",
            "price": "34535",
            "desc": "dsfsdf",
            "main_image": "NOPQR09345.png",
            "added_by": "558a526b977459300a00002b",
            "user": {
                "_id": "558a526b977459300a00002b",
                "name": "Merchant",
            }
        }, {
            "_id": "559e0a0f71c2bd2c0a000031",
            "title": "dfdxf",
            "sku": "esdf",
            "price": "345",
            "desc": "xcfgvxdvf",
            "main_image": "NOPQR09345.png",
            "added_by": "558a526b977459300a00002b",
            "user": {
                "_id": "558a526b977459300a00002b",
                "name": "Merchant",
            }
        }, {
            "_id": "559e11084a3df01808000029",
            "title": "Product 1",
            "sku": "KJH",
            "price": "12508",
            "desc": "This istest",
            "main_image": "NOPQR09345.png",
            "added_by": "558a6ade977459300a00002c",
            "user": {
                "_id": "558a6ade977459300a00002c",
                "name": "Merchant",
            }
        }]

I use grouping on user._id and i want to display name in grouping header. 我在user._id上使用分组,我想在分组标题中显示名称。 For that i use columnDefs as Follow. 为此我使用columnDefs作为Follow。

    [
       {name: 'Merchant Name', field: 'user._id', grouping: {groupPriority: 0},
                    cellTemplate: '<span style="padding:15px;">{{row.entity.user.name}}</span>'},
       {name: 'Name', field: 'title', enableCellEdit: true},
       {name: 'SKU', field: 'sku'},
       {name: 'Category', field: 'pro_category.name'},
       {name: 'Price', field: 'price', treeAggregationType: uiGridGroupingConstants.aggregation.SUM}
]

The problem is that it show username in grouped column but not showing in groupHeader rows as follow 问题是它在分组列中显示用户名但未在groupHeader行中显示如下

在此输入图像描述

How can i do that. 我怎样才能做到这一点。 Any help greatly appreciated. 任何帮助非常感谢。

This is little tricky, since the grouped row does not have any actual entity associated with it. 这有点棘手,因为分组的行没有任何与之关联的实际实体。 I think you can probably use the first row in the group's children to get the group header. 我认为您可以使用组的子项中的第一行来获取组头。

$scope.gridOptions = {
    enableFiltering: true,
    treeRowHeaderAlwaysVisible: false,
    columnDefs:[
       {name: 'Merchant Name', field: 'user._id', grouping: {groupPriority: 0},
                    cellTemplate:  '<span style="padding:15px;">{{grid.appScope.name(grid, row)}}</span>'},
       {name: 'Name', field: 'title', enableCellEdit: true},
       {name: 'SKU', field: 'sku'},
       {name: 'Category', field: 'pro_category.name'},
       {name: 'Price', field: 'price', treeAggregationType: uiGridGroupingConstants.aggregation.SUM}
],
    onRegisterApi: function( gridApi ) {
      $scope.gridApi = gridApi;
    }
  };

  $scope.name = function(grid,row,col)
  {
    if(row.groupHeader)
    {
      var entity = row.treeNode.children[0].row.entity;
      return entity.user.name;
    }
    else
    {
      return row.entity.user.name;
    }
    return "SAmple";
  }

Here is a plnkr http://plnkr.co/edit/N6I78SWkLK8wzZjHm8ds?p=preview 这是一个plnkr http://plnkr.co/edit/N6I78SWkLK8wzZjHm8ds?p=preview

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM