由于自定义行节点 ID,剪贴板中的 Ag-Grid 行顺序错误

Ag-Grid wrong row orders in clipboard due to custom row node id

Ag-grid默认的rowNodeId是一个自增数(0,1,2,3,4...)

对于我的应用程序,我使用自定义的 rowNodeId,它由网格内的值组成,例如:col_x_value + '#' + col_y_value + '#' + col_z_value :

this.gridOptions.getRowNodeId = (data) => {
    return myPkColumns
              .sort()
              .map(pk) => data[pk])
              .join('#')

问题:当我将行复制到 excel 时,行在 Excel 中的粘贴顺序与我在网格中看到的顺序不同。

订单似乎也不遵循自定义行节点 ID..

我想到的一个解决方案是使用默认的rowNodeId + 一个不可见的列来存储自定义id。但这意味着我每次需要查找特定行时都需要遍历网格。

有更好的解决方案吗?谢谢

我能想到的一个可能的解决方案是实现回调 sendToClipboard(params) 这样您就可以在将数据发送到剪贴板之前控制顺序。

来自文档 -

If you want to do the copy to clipboard yourself (ie not use the grids clipboard interaction) then implement the callback sendToClipboard(params). Use this if you are in a non-standard web container that has a bespoke API for interacting with the clipboard. The callback gets the data to go into the clipboard, it's your job to call the bespoke API.

例子here