Skip to content

Commit 7e2c837

Browse files
committed
fix: pivot sort state show error when rows and columns have same dimension #5055
1 parent d80d8f1 commit 7e2c837

3 files changed

Lines changed: 69 additions & 1 deletion

File tree

packages/vtable/examples/menu.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,10 @@ export const menus = [
301301
{
302302
path: 'pivot',
303303
name: 'pivot-autoFillWidth'
304+
},
305+
{
306+
path: 'pivot',
307+
name: 'pivot-sort-state-echo'
304308
}
305309
]
306310
},
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import * as VTable from '../../src';
2+
const PivotTable = VTable.PivotTable;
3+
const CONTAINER_ID = 'vTable';
4+
5+
export function createTable() {
6+
const option: VTable.PivotTableConstructorOptions = {
7+
records: [
8+
{ Category: 'A', 'Sub-Category': 'A1', Sales: 100, Profit: 10 },
9+
{ Category: 'A', 'Sub-Category': 'A2', Sales: 150, Profit: 15 },
10+
{ Category: 'B', 'Sub-Category': 'B1', Sales: 200, Profit: 20 },
11+
{ Category: 'B', 'Sub-Category': 'B2', Sales: 250, Profit: 25 }
12+
],
13+
rows: [
14+
{
15+
dimensionKey: 'Category',
16+
title: 'Category',
17+
showSortInCorner: true
18+
}
19+
],
20+
columns: [
21+
{
22+
dimensionKey: 'Category',
23+
title: 'Category',
24+
showSortInCorner: true
25+
}
26+
],
27+
indicators: [
28+
{ indicatorKey: 'Sales', title: 'Sales', showSortInCorner: true } as any,
29+
{ indicatorKey: 'Profit', title: 'Profit', showSortInCorner: true } as any
30+
],
31+
corner: {
32+
titleOnDimension: 'all'
33+
},
34+
pivotSortState: [
35+
{
36+
dimensions: [
37+
{
38+
dimensionKey: 'Category',
39+
isPivotCorner: true
40+
}
41+
],
42+
order: 'desc'
43+
}
44+
]
45+
};
46+
47+
const instance = new PivotTable(document.getElementById(CONTAINER_ID)!, option);
48+
(window as any).tableInstance = instance;
49+
}

packages/vtable/src/PivotTable.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1348,8 +1348,23 @@ export class PivotTable extends BaseTable implements PivotTableAPI {
13481348
for (let i = 0; i < this.pivotSortState.length; i++) {
13491349
const pivotState = this.pivotSortState[i];
13501350
const dimensions = pivotState.dimensions;
1351+
1352+
if (this.isCornerHeader(col, row)) {
1353+
const header = (this.internalProps.layoutMap as PivotHeaderLayoutMap).getHeader(col, row) as HeaderData;
1354+
if (header && header.pivotInfo && dimensions && dimensions.length > 0) {
1355+
const dim1 = dimensions[0];
1356+
const dim2 = header.pivotInfo;
1357+
if (
1358+
(dim1.isPivotCorner || (!isValid(dim1.isPivotCorner) && dim1.dimensionKey && !dim1.value)) &&
1359+
dim2.isPivotCorner &&
1360+
(dim1.dimensionKey === dim2.dimensionKey || dim1.value === dim2.dimensionKey)
1361+
) {
1362+
return pivotState.order;
1363+
}
1364+
}
1365+
}
1366+
13511367
const cell = this.getCellAddressByHeaderPaths(dimensions);
1352-
// const { col: sortCol, row: sortRow, order } = this.pivotSortState[i];
13531368
const order = pivotState.order;
13541369

13551370
if (cell && cellInRange(cellRange, cell.col, cell.row)) {

0 commit comments

Comments
 (0)