我在我的Angular应用程序中使用了Ag-grid,网格中的数据是从web服务中填充的。我在这个网格中实现了单元格编辑,所以当我单击其中一列时,整个行将是可编辑的,而当我在网格外部单击时,将停止编辑。以下是html和组件文件中的代码:
<ag-grid-angular #agGrid style="width: 100%; height: 600px;" class="ag-theme-balham left" [rowData]="rowData" [columnDefs]="columnDefs"
[gridOptions]="gridOptions" rowSelection="multiple" pagination=true (rowSelected)="onRowSelected($event)">
</ag-grid-angular>
component.ts文件:
this.gridOptions = {
defaultColDef: {
editable: (event: any) => {
if (this.isGridDataEditable) {
return true;
} else {
return false; // true/false based on params (or some other criteria) value
}
},
filter: true
},
singleClickEdit: true,
stopEditingWhenGridLosesFocus: true,
paginationPageSize: 20,
editType: 'fullRow',
onCellValueChanged: (event: any) => {
},
onRowValueChanged: (event: any) => {
},
onRowEditingStopped: (event: any) => {
}
};
}
列定义是基于来自web api的响应动态生成的。当编辑停止时,如果数据发生变化,那么我必须调用web api来更新数据,所有这些都像expected.But一样工作,我想在网格上方添加一个保存和取消按钮,当用户单击保存然后调用web api时,单击取消按钮应该会将网格数据恢复为旧值。我遇到了stopEditing接口(True),但它不工作。你能告诉我如何才能实现这个功能吗?
发布于 2019-04-11 16:47:14
尝试将stopEditingWhenGridLosesFocus
设置为false
。
然后在网格上方添加两个按钮Save和Cancel。
单击保存。调用onSave
函数,其定义为
onSave() {
this.agGrid.api.stopEditing();
this.callWebApi();
}
单击cancel时,调用onCancel
函数,其定义为
onCancel() {
this.agGrid.api.stopEditing(true);
}
如果这是你要找的,请告诉我。
https://stackoverflow.com/questions/55584289
复制相似问题