Angular 2 + ag-grid / 编辑整列
Angular 2 + ag-grid / Edit entire column
我想编辑具有相同值的整个列。
我的农业网格如下所示:image of the grid
我想做的是将列 Etat
的所有值更改为 arrêté
,但我现在不能让它工作。
这是我尝试过的代码:
private gridOptions: GridOptions;
public rowData: any[];
constructor() {
this.stopTrains();
this.gridOptions = {};
this.gridOptions.columnDef = [
...
{
headerName: 'Etat',
field: 'etat',
...
editable: true
}
...
];
}
stopTrains() {
var rowData: any[] = [];
rowData.push({
etat: 'arrêté'
})
this.rowData = rowData;
}
stopTrains()
当我点击按钮时被调用。
这是我的建议:
stopTrains() {
//loop through current row data and set the etat key to 'arrêté'
this.gridOptions.api.forEachNode(params=>params.data.etat = 'arrêté')
//refresh the view so that the changes take effect
this.gridOptions.api.refreshView()
}
您也可以使用 forEachNodeAfterFilter
,它只会更改网格中的可见节点。
这里有一个plunker用于演示:
我想编辑具有相同值的整个列。
我的农业网格如下所示:image of the grid
我想做的是将列 Etat
的所有值更改为 arrêté
,但我现在不能让它工作。
这是我尝试过的代码:
private gridOptions: GridOptions;
public rowData: any[];
constructor() {
this.stopTrains();
this.gridOptions = {};
this.gridOptions.columnDef = [
...
{
headerName: 'Etat',
field: 'etat',
...
editable: true
}
...
];
}
stopTrains() {
var rowData: any[] = [];
rowData.push({
etat: 'arrêté'
})
this.rowData = rowData;
}
stopTrains()
当我点击按钮时被调用。
这是我的建议:
stopTrains() {
//loop through current row data and set the etat key to 'arrêté'
this.gridOptions.api.forEachNode(params=>params.data.etat = 'arrêté')
//refresh the view so that the changes take effect
this.gridOptions.api.refreshView()
}
您也可以使用 forEachNodeAfterFilter
,它只会更改网格中的可见节点。
这里有一个plunker用于演示: