在服务器分页/排序/过滤模式下将数据导出到CSV [英] Export data to CSV in server pagination / sorting / filtering mode
问题描述
我正在尝试导出 ag-网格数据到CSV.
I am trying to export the ag-grid data to CSV.
问题是,在考虑paginationPageSize
、maxBlocksInCache
时,它仅导出可见数据OR从HTTP调用接收到的内存数据,cacheBlockSize
等.不是整个数据集.
The issue is, it exports only the visible data OR the in-memory data received from HTTP call while considering paginationPageSize
, maxBlocksInCache
, cacheBlockSize
etc. in the grid. Not the entire data-set.
我浏览了以下链接,但没有得到太多帮助.
I went through below links, but couldn't get much help.
有什么办法可以做到这一点吗?或者这完全不可能?
Is there any way we can achieve this? Or this is altogether not possible?
推荐答案
我就是这样解决的 -
This is how i solved this -
- 从数据源中获取您需要的所有行
- 克隆 gridapi 对象
- 从克隆的 gridapi 中获取服务器端缓存
- 对其进行处理,使其充满您获取的数据
- 在克隆的 gridapi 上运行导出到 excel 方法
- ...
- 利润
const gapi = cloneDeep(this.gridApi);//克隆 gridApi
const gapi = cloneDeep(this.gridApi); // clone gridApi
const blocks = gapi['serverSideRowModel'].rootNode.childrenCache.blocks;//抑制私有警告/错误的对象符号
const blocks = gapi['serverSideRowModel'].rootNode.childrenCache.blocks; // object notation to suppress private warning/err
// swap rows cache with fetched data
for (let i = 0, j = 0; i < Math.ceil(results.length/this.paginationPageSize); i++) {
// we alter relevant block, or if it is not loaded yet we clone 1st one and alter it
const block = blocks[i] || cloneDeep(blocks[0]);
block.rowNodes.forEach(n => n.data = results[j++]);
blocks[i] = block;
}
gapi['serverSideRowModel'].rootNode.childrenCache.blocks = blocks;
gapi.exportDataAsExcel(params);
这篇关于在服务器分页/排序/过滤模式下将数据导出到CSV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!