我要在Angular7上测试Ag-Grid。我想做的一件事是检测网格中的单元格更改,但是我无法触发oncellvaluechanged()。我只是在JS和Angular中迈出第一步,所以也许这是一个愚蠢的问题。谢谢
我在app.component.html中的网格定义:
<ag-grid-angular style="width: 950px; height: 320px;" class="ag-theme-balham"
[enableSorting]="true" [enableFilter]="true"
[rowData]="stocks" [columnDefs]="columnDefs" rowSelection="multiple"
[enterMovesDownAfterEdit]="true"
[enterMovesDown]="true">
(cellValueChanged)="onCellValueChanged($event)"
</ag-grid-angular>
我的app.component.ts:
import { Component , OnInit} from '@angular/core';
import { StockService } from './stock.service';
import { stock } from './stock';
import {MatButtonModule, MatCheckboxModule} from '@angular/material';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app';
stocks: stock[];
public loading = false;
pedidos: stock[];
constructor(private stockService: StockService) {this.stocks = []; }
columnDefs = [
{headerName: 'Código',
field: 'cod_ins',
width: 150,
suppressSizeToFit: true
},
{headerName: 'Cantidad',
field: 'pedido',
width: 110,
editable: true,
type: 'numericColumn',
}
];
onCellValueChanged(params: any) {
console.log('Estoy en onCellValueChanged !!!');
}
}
uh,问题是>在错误的位置:
[enterMovesDown]="true">
(cellValueChanged)="onCellValueChanged($event)"
应该在这里:
[enterMovesDown]="true"
(cellValueChanged)="onCellValueChanged($event)">
编译器发出的错误。
这是因为rowdata没有更改(this.stocks = [] - alwasy,但是如果要在oncellvaluechanged()方法中检测到它,则应将其更改尝试使用:
@Input() stocks
或尝试通过轮询从服务器调查中获取库存