ag-grid - ag-grid - 使用无限行模型添加行
问题描述
我需要在无限滚动的 ag-grid 中添加一个新行。有类似的问题,例如这个。但是我的情况非常不同。我在 ag-grid 中使用内联编辑,并有一个添加新行的按钮。有一个提交按钮,用户可能会也可能不会按下。因此,当新行添加到客户端站点时,不会立即修改服务器上的数据。当我使用客户端模型时,一切都很简单——我从服务器获取行,可以向数组添加新行并在 ag-grid 上调用 setRowData。但是,此功能不适用于无限滚动。如果这很重要,我正在使用 angular 2+。
我试图调用 applyTransaction 但在控制台中出现错误:
g-Grid:updateRowData() 仅适用于 ClientSideRowModel。使用 InfiniteRowModel 在 v23.1 中已弃用并在 v24.1 中删除
似乎 a-grid 只是删除了没有可替换的功能。
解决方案
我个人没有使用带角度的 agGrid,但如果您使用的是infiniteRow
模型,则可以使用setDataSource
强制表格刷新数据的方法。
该setDataSource
方法接受具有两个最小参数的对象:
{
rowCount: null,
getRows: (params) =>{
// here you can do your server call or, you can pass the data you want instead.
// you also need to do one thing at the end of your row generation, call this method
//`rows` is the array of rows you want to show, `totalRowsNumber` is the number of rows in total, including those that are not shown (the ones in later pages)
params.successCallback(rows, totalRowsNumber);
}
}
使用gridApi.setDatasource(dataSourceObject)
推荐阅读
- python - Apache Spark 无法计算平均值并将结果写入 Apache Kafka
- ruby-on-rails - Rails 已安装,但当我尝试使用它时出现“此系统上当前未安装 Rails”错误
- global-payments-api - GlobalPayments HPP - 货币 CAD 不允许
- reactjs - 如何将数据从一个组件传递和显示到另一个组件?
- java - 更改为深色主题时,微调器文本不可见
- python - “系列”对象没有属性“列”
- r - 从 R 中的数据矩阵中获取向量范数
- c# - Button.DialogResult、Form.ShowDialog 和异步事件处理程序超出预期的执行顺序
- python - 从 HTML 中的 var 中提取字典
- python - 将“Manager”从 Flask-Script 迁移到 Flask CLI