Reputation: 33
I'm testing ag-grid on angular 7. One of the things I want to do is detect cell changes in the grid, but I can't get the onCellValueChanged() fired. I'm just making my first steps in js and angular so maybe this is a silly question. Thanks
My grid definition in 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>
My 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 !!!');
}
}
Upvotes: 1
Views: 3315
Reputation: 33
Uh, the problem was that the > was in the wrong place:
[enterMovesDown]="true">
(cellValueChanged)="onCellValueChanged($event)"
It should be here:
[enterMovesDown]="true"
(cellValueChanged)="onCellValueChanged($event)">
No error emitted by the compiler.
Upvotes: 1
Reputation: 121
This happens because rowData is not changing (this.stocks = [] - alwasy, but it should be changed if you want detect it in onCellValueChanged() method) Try to use:
@Input() stocks
or try to get stock from the server survey by polling
Upvotes: 0