Skip to content

Commit

Permalink
fix: 修复复制整行时错位 (#2278)
Browse files Browse the repository at this point in the history
* fix: 修复复制整行时错位

* fix: 修复选行复制时的排序问题

---------

Co-authored-by: owen.wjh <owen.wjh@alibaba-inc.com>
  • Loading branch information
serializedowen and owen.wjh authored Aug 7, 2023
1 parent da1a5ab commit 8076481
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/s2-core/__tests__/unit/utils/export/copy-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ describe('List Table Core Data Process', () => {
});

const data = getSelectedData(ss);
expect(data).toBe('2367\t浙江省_formatted\t绍兴市\t家具\t桌子');
expect(data).toBe('浙江省_formatted\t绍兴市\t家具\t桌子\t2367');
});

// https://github.com/antvis/S2/issues/1770
Expand Down Expand Up @@ -256,7 +256,7 @@ describe('List Table Core Data Process', () => {
stateName: InteractionStateName.SELECTED,
});
const data = getSelectedData(s2);
expect(data).toBe('2330\t四川省\t乐山市\t家具\t桌子');
expect(data).toBe('四川省\t乐山市\t家具\t桌子\t2330');

s2.interaction.changeState({
stateName: InteractionStateName.ALL_SELECTED,
Expand Down Expand Up @@ -286,7 +286,7 @@ describe('List Table Core Data Process', () => {
stateName: InteractionStateName.SELECTED,
});
const data = getSelectedData(s2);
expect(data).toBe('7234\t浙江省\t宁波市\t家具\t沙发');
expect(data).toBe('浙江省\t宁波市\t家具\t沙发\t7234');
s2.interaction.changeState({
stateName: InteractionStateName.ALL_SELECTED,
});
Expand Down
7 changes: 7 additions & 0 deletions packages/s2-core/src/utils/export/copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,14 @@ const processTableRowSelected = (
const matrix = displayData
.filter((_, i) => selectedRows.map((row) => row.rowIndex).includes(i))
.map((entry) => {
// 确保顺序和表格中的列顺序一致
const idxMap = spreadsheet.getColumnNodes().reduce((prev, curr, idx) => {
prev[curr.field] = idx;
return prev;
}, {});

return Object.keys(entry)
.sort((a, b) => idxMap[a] - idxMap[b])
.map((cName) =>
spreadsheet.getColumnNodes().find((n) => n.field === cName),
)
Expand Down

1 comment on commit 8076481

@vercel
Copy link

@vercel vercel bot commented on 8076481 Aug 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

antvis-s2 – ./

antvis-s2-git-master-antv-s2.vercel.app
antvis-s2.vercel.app
antvis-s2-antv-s2.vercel.app

Please sign in to comment.