如何在平面结构化数据上按分组/透视农业网格?

时间:2019-09-20 15:19:47

标签: angular ag-grid ag-grid-angular

我想在ag-grid中显示数据,如下面的屏幕截图所示。我已经使用数据透视表和父子关系尝试了此操作。列标题的数据应该从Json动态绑定(例如:-来自屏幕快照年ie2002,2003 ...应该来自Json)但是我被卡住了这个。谁能帮忙吗? 预期设计的屏幕截图:-https://i.stack.imgur.com/tWGop.png

以下是我尝试使用数据透视表进行的操作:-https://plnkr.co/edit/qZOo8YBtMG5kB7elsaED?p=preview 并使用父子关系:-https://stackblitz.com/edit/angular-ag-grid-header-groupheader-component-ki6wwz?file=app/app.component.ts

使用数据透视模式:-

this.columnDefs = [
  {
    headerName: "Country",
    field: "country",
    width: 120,
    rowGroup: true,
    enableRowGroup: true
  },
  {
    headerName: "Year",
    field: "year",
    width: 90,
    pivot: true,
    enablePivot: true
  },
  {
    headerName: "Gold",
    field: "gold",
    width: 100,
    aggFunc: "sum"
  },
  {
    headerName: "Silver",
    field: "silver",
    width: 100,
    aggFunc: "sum"
  },

];   

使用亲子:-

this.columnDefs = [
  {
    headerName: "Country",
    field: "country",
    width: 120,
    suppressMenu: true
  },     
   {
    headerName: "2002",       
    children: [          
      {
        headerName: "Gold",
        field: "gold",
        width: 90,
        sortable: false,           
      },
      {
        headerName: "Silver",
        field: "silver",
        width: 90,
        sortable: false,           
      }
      ]
  },          

];

0 个答案:

没有答案
相关问题