来自对象的角度 ui-grid 分组 [英] angular ui-grid grouping from object

查看:33
本文介绍了来自对象的角度 ui-grid 分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中使用

I am using ui-grid v3.0.0-rc.22 in my application.

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. For that i use columnDefs as 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

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

这篇关于来自对象的角度 ui-grid 分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆