微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

设置相同值时不触发 ag-grid valueSetter

如何解决设置相同值时不触发 ag-grid valueSetter

我们在项目中使用 ag-grid,刚刚从版本 20.1.0 升级到最新版本 (25.0.1)。 注意到了一些已修复的差异,但我们发现了一个我不知道如何修复的问题。

问题是在旧版本中,即使值没有改变,“ColDef”上的“valueSetter”也会被触发。 我的意思是,我们在列中有一个下拉列表,其中设置了一个值,例如 one

现在,当我打开下拉菜单时,我会看到三个选项:

one
two
three

并再次选择 one 我希望触发“valueSetter”。我们有一些必须再次运行的逻辑,因为位于该行下方的组中的其他一些行可能需要更改。

我想我能够找到原因,它在 ag-grid-community.cjs.js 文件中,第 #20676 行:

函数CellComp.prototype.stopEditing中:

    if (newValueExists && newValue !== oldValue) { // The equals here is causing the problem for us
        // we suppressRefreshCell because the call to rowNode.setDataValue() results in change detection
        // getting triggered,which results in all cells getting refreshed. we do not want this refresh
        // to happen on this call as we want to call it explicitly below. otherwise refresh gets called twice.
        // if we only did this refresh (and not the one below) then the cell would flash and not be forced.
        this.suppressRefreshCell = true;
        this.rowNode.setDataValue(this.column,newValue);
        this.suppressRefreshCell = false;
    }

正如您在第一行中看到的那样,它检查 newValue !== oldValue 是否存在,以前不存在(它是在版本 23 中引入的)。我觉得这不是一个好的解决方案,我们应该有能力覆盖这个equals函数

但是无论如何,有人知道如何规避这个问题吗?我想暂时更改下拉列表中当前设置的值并为其添加额外的空间可能会让我完成此操作,但我想知道是否有更好的解决方案。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。