【问题标题】:Updating row data in ag-grid angular4在 ag-grid angular4 中更新行数据
【发布时间】:2020-01-09 15:06:11
【问题描述】:

在 AngularJS 中,我可以通过执行 `gridOptions.api.setRowData(rowData) 之类的操作来更新网格的行数据。

我现在正尝试在 Angular4 应用程序中执行此操作。我的 TS 文件有:

import { Component } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { AgGridModule } from 'ag-grid-angular/main';
import { GridOptions, RowNode } from 'ag-grid/main';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'app a4';
  studentList = {};
  gridOptions = {};


   constructor(private http: HttpClient){
       this.gridOptions = <GridOptions>{
           context: {
               componentParent: this
           },
           columnDefs: this.createColumnDefs(),
           rowDefs: this.studentList,
       };
   }

   ngOnInit(): void {
     this.http.get('students/list').subscribe(data => {
       this.studentList = data;
       console.log(data);
       this.gridOptions.api.setRowData(this.studentList);
     });
   }

       private createColumnDefs() {
           return [
               {
                   headerName: "Name",
                   field: "name",
                   width: 400
               },
               {
                   headerName: "SSN",
                   field: "ssn",
                   width: 400,
               }
           ];
       }

}

但是,在编译时,angular-cli 不喜欢 `api.根据 AG-Grid 文档,这似乎仍然是正确的做事方式。我无法从示例中看出我缺少什么。

ERROR in C:/Projects/spring-boot-mvc-test/frontend/src/app/app.component.ts (31,25): Property 'api' does not exist on type '{}'.

【问题讨论】:

    标签: angular ag-grid


    【解决方案1】:

    ngOnInit 中的 gridOptions 似乎为空。 试试这个:

    ngOnInit(): void {
      let that: this = this;
      this.http.get('students/list').subscribe(data => {
        this.studentList = data;
        console.log(data);
        that.gridOptions.api.setRowData(this.studentList);
      });
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-29
      • 2021-03-10
      • 2021-12-06
      • 1970-01-01
      • 2021-11-20
      • 2017-12-18
      相关资源
      最近更新 更多