ag-grid(React)具有用于导出的自定义列

huangapple go评论106阅读模式
英文:

ag-grid (React) having custom column for exports

问题

以下是翻译的部分:

假设我有以下数据:

[
  { name: 'Cesar', date: '2023-10-10 05:10AM' },
  { name: 'James', date: '2023-10-11 10:10AM' }
]

以及以下用于 ag-grid 的 columnDefs

[
  { headerName: 'Name', field: 'name' },
  { headerName: 'Date', field: 'date' }
]

如果我导出它(CSV 或 Excel),我会得到完全相同的两列,这是默认行为。

但是,我如何使导出功能(CSV 和 Excel)将日期列拆分为两列呢?这是我们希望在导出文件中看到的数据结构。

| Name  | Date       | Time    |
| ----- | ---------- | ------- |
| Cesar | 2023-10-10 | 05:10AM |
| James | 2023-10-11 | 10:10AM |

我尝试过的方法

  1. 使用 processCellCallbackprocessHeaderCallbackdate 列拆分为 2 列;但是这 "2 列" 被呈现在同一列中 😞。

两列合并在一起

  1. 我尝试向我的 columnDefs 添加第三列,该列设置为 hide: truelockVisible: true
[
  { headerName: 'Name', field: 'name' },
  { headerName: 'Date', field: 'date' }, 
  { headerName: 'Time', field: 'date', hide: true, lockVisible: true } // 使用正确的 getter
]

这部分工作部分因为该列显示在列菜单的 "Columns" 选项卡中。

列显示在菜单中

复选框被禁用,因此列永远不会显示;但是我们需要 "时间" 列仅在导出的文件中可用,而不是在用户界面中可见。 😞

英文:

Say I have the following data:

[
  { name: 'Cesar', date: '2023-10-10 05:10AM' },
  { name: 'James', date: '2023-10-11 10:10AM' }
]

and I have the following columnDefs for ag-grid:

[
  { headerName: 'Name', field: 'name' },
  { headerName: 'Date', field: 'date' }
]

If I export it (CSV or Excel) I get the same exact 2 columns, which is the default behavior.

But, how can I have the export functionality (CSV and Excel) to split the date column into two columns? This is the data structure we expect to see in the exported files.

| Name  | Date       | Time    |
| ----- | ---------- | ------- |
| Cesar | 2023-10-10 | 05:10AM |
| James | 2023-10-11 | 10:10AM |

Things I've tried

  1. processCellCallback and processHeaderCallback to split the date column into 2 columns; but the "2 columns" are rendered in the same column 👎

two columns in one

  1. I tried adding a third column to my columnDefs which is hide: true and lockVisible: true:
[
  { headerName: 'Name', field: 'name' },
  { headerName: 'Date', field: 'date' }, 
  { headerName: 'Time', field: 'date', hide: true, lockVisible: true } // with the right getter
]

This works partially because the column shows up in the Column Menu columnsMenuTab
column showing in the menu

The checkbox is disabled, so the column cannot be shown ever; but we need the "time" column to be only available on the exported files, not in the UI

答案1

得分: 0

祝贺!您离解决这个谜题非常接近。

suppressColumnsToolPanel

如果您不希望此列或分组出现在列工具面板中,请将其设置为true。

以下是一个示例:

ag-grid(React)具有用于导出的自定义列

https://plnkr.co/plunk/UWTdLRgBM5H9ooLh

英文:

Congrats! You're very close to solve this puzzle.

> suppressColumnsToolPanel
>
> Set to true if you do not want this column or group to appear in the
> Columns Tool Panel.

{ 
  headerName: "Time", 
  field: 'date', 
  hide: true, 
  suppressColumnsToolPanel: true // this one
}

Here's an example

ag-grid(React)具有用于导出的自定义列

https://plnkr.co/plunk/UWTdLRgBM5H9ooLh

huangapple
  • 本文由 发表于 2023年7月13日 22:30:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76680536.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定