小编rds*_*s80的帖子

使用 ag-grid 和 angular 2 时发送多个请求

我正在从 ASP.NET Webapi 检索数据并在 angular 2 应用程序中填充 ag-grid。

数据填充在 ag-grid 中,但我注意到开发人员工具的网络选项卡中的请求被请求淹没并最终超时。我不确定为什么会这样。似乎 web api 被无限调用。

这是角度代码:

事件详细信息.component.ts

import { IEvent } from 'model/event.model';
import { EventService } from 'services/event.service';
import { Component, OnInit } from '@angular/core';
import {GridOptions} from "ag-grid/main";

@Component({
  selector: 'event-details',
  templateUrl: './event-details.component.html',
  styleUrls: ['./event-details.component.css']
 })
export class EventDetailsComponent implements OnInit {
events: IEvent[];
gridOptions: any = [];
errorMessage: string;
error: any;

constructor(private eventService: EventService) {
  this.gridOptions = <GridOptions>{};
}

columnDefs() {
return [
    {headerName: "Event ID", field: "id", …
Run Code Online (Sandbox Code Playgroud)

asp.net-web-api2 ag-grid angular

6
推荐指数
1
解决办法
366
查看次数

从 ag-grid 列获取复选框值

我在 ag-grid 中有一个复选框,我按以下方式显示:

  {header: 'Cancel', 
    field: 'IsCancel', 
    cellRenderer: params => {
      return `<input type='checkbox' ${params.value ? 'checked': ''} />`
    }  
  }
Run Code Online (Sandbox Code Playgroud)

我想要实现的是,当用户单击“保存”按钮时,我会浏览每一行并找出已选中哪个复选框。

我尝试使用下面的代码来找出已选中哪个复选框。不幸的是,即使我选中 ag-grid 中的复选框,node.data.IsCancel 也是 false:

  saveCustomer() {
    this.api.forEachNode(this.printNode)
  }

  printNode(node, index) {
    console.log('Customer Number is: ' + node.data.CustomerNumber);
    console.log('Cancel is: ' + node.data.IsCancel);
    if (node.data.IsCancel.checked) {
      console.log('Customer Number in checked is: ' + node.data.CustomerNumber);
    }
  }
Run Code Online (Sandbox Code Playgroud)

这是所有代码:

取消.component.html

<div *ngIf="loadCancellation">
  <ag-grid-angular class="ag-fresh"
    [columnDefs]="columnDefs"
    [rowData]="customerNames"
    (gridReady)="onGridReady($event)"
    class="ag-theme-balham">
  </ag-grid-angular>
  <br/>
  <button mat-raised-button color="primary" (click)="saveCustomer()">Save</button>
</div>
Run Code Online (Sandbox Code Playgroud)

取消.component.ts

import { Component, Input, …
Run Code Online (Sandbox Code Playgroud)

ag-grid angular ag-grid-angular

4
推荐指数
1
解决办法
1万
查看次数