AG 网格:禁用编辑行,除非编辑了保存的行



我有一个要求,一旦在 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))
}

到目前为止,这正在工作,但是如果有的话,我正在寻找一些强大的解决方案。 谢谢

您可以指定一个函数,该函数为列定义的"可编辑"属性返回布尔值(而不是指定布尔值(。

每次用户尝试编辑单元格时,网格都会评估此函数。 如果函数返回 true,则继续编辑,如果返回 false,则单元格不会进入编辑模式。

因此,例如,如果您保留在进行编辑时设置的"脏"标志,并在保存时清除,则可以使用

editable: () => return !this.dirty

确保使用上述"胖箭头功能",否则可能无法正常工作。

最新更新