我们在 Angular 8 中有一个新项目,我们正在使用 AG Grid,现在用户希望在有人编辑一行并且不保存它移动到另一条记录/行的情况下触发验证。它应该说先保存您的数据。
我在 onRowChange 功能上尝试过相同的操作,但是用户不希望在单击时触发验证,他们只希望在编辑某些内容时触发验证。
下面是我所做的示例代码,但这并没有完全达到目的,有人可以帮我吗?我也尝试过 onValueChange() ,它没有用。
代码:
onRowClick(event: any) {
if (this.cellChangeCount === 0) {
this.UnsavedNodeIndex = event.node.rowIndex;
this.UnsavedNodeID = event.data.ID;
}
this.commonAgGrid.commonAgGridfunc(event, this.gridApi, this.cellChangeCount, this.UnsavedNodeIndex, this.newRowClicked,
this.UnsavedNodeID, this.colName);
this.cellChangeCount++;
}
commonAgGridfunc(event: any, gridApi, cellChangeCount, UnsavedNodeIndex, newRowClicked, UnsavedNodeID, colName) {
cellChangeCount = cellChangeCount == 0 ? 0 : cellChangeCount;
cellChangeCount = newRowClicked == true ? 0 : cellChangeCount;
if (cellChangeCount !== 0 && (UnsavedNodeID != event.data.ID) && !newRowClicked) {
if (typeof UnsavedNodeID != "undefined") {
this.alertService.info("Save data first.");
setTimeout(() => this.alertService.clear(), 2000);
this.onBtStartEditing(gridApi, UnsavedNodeIndex, colName);
}
}
if (newRowClicked == true && (UnsavedNodeID != event.data.ID)) {
gridApi.stopEditing();
gridApi.setFocusedCell(0, colName);
gridApi.startEditingCell({
rowIndex: 0,
colKey: colName,
});
gridApi.forEachNode(node => node.rowIndex == 0 ? node.setSelected(true) : node.setSelected(false))
}
}