【问题标题】:AG-GRID does not an applyTransaction method on gridApiAG-GRID 不是 gridApi 上的 applyTransaction 方法
【发布时间】:2021-11-09 00:12:25
【问题描述】:

这是我的onGridReady() 方法:

onGridReady = (grid) => {
    this.gridInstance = grid;
    this.resizeColumnsToFit();
    this.props.setIsLoading(false);
    this.gridApi = grid.api;
    this.gridColumnApi = grid.columnApi;
    console.log("gridOptions is", this.gridOptions);
};

然后在一个按钮点击我有:

const sel = this.gridApi.getSelectedRows();
console.log(sel); // this one is good.
const res = this.gridApi.applyTransaction({ remove: sel }); // this one is not good

但我收到此错误:

Uncaught (in promise) TypeError: _this.gridApi.applyTransaction is not a function

我试图从这里效仿他们自己的例子:https://www.ag-grid.com/react-data-grid/data-update-transactions/

那我做错了什么?

【问题讨论】:

  • console.log(sel);你在这里得到什么?
  • @Mahi 我得到了关于每个选定行的信息,这是我拥有的 16 列,每列都有值。就像每一行的每一列的值一样。

标签: reactjs ag-grid ag-grid-react


【解决方案1】:

applyTransaction 需要版本 23.1.0

然后检查sel是否存在:-

this.gridApi?.applyTransaction({ remove: sel });

版本低于23.1.0,使用

this.gridApi?.updateRowData({ remove: sel })

https://www.ag-grid.com/ag-grid-changelog/?fixVersion=23.1.0

【讨论】:

  • 有什么意义,好吧,如果它不存在,它不会崩溃,但我们的问题是为什么我不能调用它,而不是为什么当我调用它时它会崩溃。我想调用它,但它没有找到那个方法。
  • 你能更新你正在使用的模块和版本号吗?
  • 看起来对我来说是 21.1.1 版
猜你喜欢
  • 2020-09-06
  • 2021-04-23
  • 2020-09-26
  • 2019-11-15
  • 2020-03-10
  • 2021-08-26
  • 2020-09-09
  • 2020-03-08
  • 2020-08-08
相关资源
最近更新 更多