首页 > 解决方案 > Angular Ag Grid - 有没有人想出一种方法来等待单元节点更新发生然后触发一个函数,比如回调?

问题描述

cellChanged.node.setDataValue(fieldChanged, oldValue)在事件发射器内部使用,并且在函数完成执行后(cellValueChanged)无法弄清楚如何调用函数。setDataValue我需要这样做来检查用户是否有权更新单元格。

这是检查的完整代码:

if(this.showPaywallNotification) {

      // Okay, so the budget is above what we allow HOWEVER...
      if(budget > BUDGET_AMOUNT) {

      this.showPaywallNotification = false;
      cellChanged.node.setDataValue(fieldChanged, oldValue)

      // Note: This timeout is in place to prevent the infinite updating bug
      // This is problematic because if the user changes the cells fast enough, they can get around the paywall. If I change the timeout to be smaller, the resulting change triggers the update, which ends up creating an infinite loop of updates.
      setTimeout(() => {
           this.showPaywallNotification = true;
      }, 230)
  }

}

有没有一种方法可以用更好的方法替换我的setTimeout()功能,以始终确保用户无法通过比超时执行速度更快地更新单元格来绕过我的付费墙?

标签: ag-gridag-grid-angular

解决方案


您不必进行投票。setDataValue不是异步函数。

此外,onCellValueChanged如果您调用 ,将不会再次被调用node.setDataValue

看看这个 plunk:Cell Editing - Revert to old value。尝试将任何Age值更新为负值。

onCellValueChanged($event) {
  if ($event.colDef.field === 'age' && $event.newValue < 0) {
    // debugger
    $event.node.setDataValue('age', $event.oldValue);
    console.log('value reverted');
  }
}

让我知道是否有不清楚的地方,或者这还不够。


推荐阅读