我有一个要求,一旦在 ag 网格中编辑了行,除非该行已保存,否则不应允许编辑其他行。
有没有办法实现它?
我正在使用 onRowClick($event) 方法进行一些验证,示例如下:
onRowClick(event: any) {
if (this.cellChangeCount === 0) {
this.UnsavedNodeIndex = event.node.rowIndex;
this.UnsavedNodeID=event.data.ID;
console.log(event.node);
}
if (this.cellChangeCount !== 0 && (this.UnsavedNodeID!=event.data.ID ) && !this.newRowClicked) {
if(typeof this.UnsavedNodeID !="undefined"){
this.alertService.info("Save data first.");
this.onBtStartEditing();
}
}
if(this.newRowClicked==true && (this.UnsavedNodeID!=event.data.ID ) ){
this.gridApi.stopEditing();
this.gridApi.setFocusedCell(0, 'ColName');
this.gridApi.startEditingCell({
rowIndex: 0,
colKey: 'ColName',
});
this.gridApi.forEachNode(node=> node.rowIndex==0 ? node.setSelected(true) : node.setSelected(false))
}
this.cellChangeCount++
}
onBtStartEditing() {
this.gridApi.stopEditing();
this.gridApi.setFocusedCell(this.UnsavedNodeIndex, 'COlName');
this.gridApi.startEditingCell({
rowIndex: this.UnsavedNodeIndex,
colKey: 'ColName',
});
this.gridApi.forEachNode(node=> node.rowIndex==this.UnsavedNodeIndex ? node.setSelected(true) : node.setSelected(false))
}
到目前为止,这正在工作,但如果有的话,我正在寻找一些强大的解决方案。谢谢