I am trying to export the ag-grid data to CSV.
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 -
const gapi = cloneDeep(this.gridApi); // clone gridApi
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With