【问题标题】:How to display data in angular ag grid如何在角度 ag 网格中显示数据
【发布时间】:2020-01-10 04:02:38
【问题描述】:

https://stackblitz.com/edit/ag-grid-angular-hello-world-pvtbsw?file=src/app/app.component.ts

如何在 ag 网格中显示这些数据?

输出应该是这样的。

【问题讨论】:

    标签: javascript angular typescript


    【解决方案1】:

    app.component.html

    <ag-grid-angular 
        style="width: auto; height: 300px;" 
        class="ag-theme-balham"
        [rowData]="rowData" 
        [columnDefs]="desktopDefaultCols"
        [modules]="modules">
    
    </ag-grid-angular>
    

    app.component.ts

    import { Component } from '@angular/core';
    
    import {AllCommunityModules} from "@ag-grid-community/all-modules";
    
    @Component({
      selector: 'my-app',
      templateUrl: './app.component.html',
      styleUrls: [ './app.component.scss' ]
    })
    export class AppComponent  {
       desktopDefaultCols = [
        {
            headerName: "January19", 
             children: [
               {headerName: "PRN 1",
               field: 'prn1'},
               {headerName: "PRN",
               field: 'prn'}
             ]
        },
        {
            headerName: "March19",
            children: [
              {headerName: "Total"}
             ]
        },
        {
            headerName: "May19", 
            children: [
              {headerName: "Total"}
             ]
        },
        {
            headerName: "June19", 
            children: [
              {headerName: "Total"}
             ]
        }
    
    ];
    
    
        columnDefs = [
            {field: 'make' },
            {field: 'model' },
            {field: 'price'}
        ];
    
        rowData = [
            { prn1: '10', prn: '0'},
             { prn1: '3', prn: '10'},
              { prn1: '0', prn: '1'},
            { prn1: '0', prn: '0'},
            { prn1: '0', prn: '0'},
        ];
    
        modules = AllCommunityModules;
    
    }
    

    演示:https://stackblitz.com/edit/angular-tsy8c1

    【讨论】:

      猜你喜欢
      • 2020-10-05
      • 2022-01-14
      • 2021-01-15
      • 2020-03-19
      • 2019-02-14
      • 2020-03-22
      • 2021-04-02
      • 1970-01-01
      • 2020-10-28
      相关资源
      最近更新 更多