Skip to content

Commit 3c2ac91

Browse files
committed
chore: fix sticky expand
1 parent 278a471 commit 3c2ac91

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
lines changed

src/StaticTable/BodyGrid.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ const Grid = React.forwardRef<GridRef, GridProps>((props, ref) => {
5050
() => columnsWidth.map(colWidth => colWidth[2]),
5151
[columnsWidth],
5252
);
53-
console.log('~~~~>', flattenColumns, columnsWidth);
5453

5554
React.useEffect(() => {
5655
columnsWidth.forEach(([key, width]) => {

src/StaticTable/useWidthColumns.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,17 @@ export default function useWidthColumns<RecordType>(
4848
let restCount = missWidthCount;
4949
const avgWidth = restWidth / missWidthCount;
5050

51-
const fillWidth = (cols: ColumnsType<RecordType>, parentKey: string) =>
52-
cols.map((col: any, index) => {
53-
const mergedKey = `${parentKey}-${index}`;
54-
51+
const fillWidth = (cols: ColumnsType<RecordType>) =>
52+
cols.map((col: any) => {
5553
const clone = {
56-
key: mergedKey,
5754
...col,
5855
};
5956

6057
const colWidth = parseColWidth(scrollX, clone.width);
6158
const hasChildren = col.children?.length;
6259

6360
if (hasChildren) {
64-
clone.children = fillWidth(col.children, mergedKey);
61+
clone.children = fillWidth(col.children);
6562
}
6663

6764
if (colWidth) {
@@ -78,7 +75,7 @@ export default function useWidthColumns<RecordType>(
7875
return clone;
7976
});
8077

81-
return fillWidth(columns, 'key');
78+
return fillWidth(columns);
8279
}
8380

8481
return columns;

src/hooks/useColumns.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,23 @@ export function convertChildrenToColumns<RecordType>(
3535
});
3636
}
3737

38-
function flatColumns<RecordType>(columns: ColumnsType<RecordType>): ColumnType<RecordType>[] {
38+
function flatColumns<RecordType>(
39+
columns: ColumnsType<RecordType>,
40+
parentKey = 'key',
41+
): ColumnType<RecordType>[] {
3942
return columns
4043
.filter(column => column && typeof column === 'object')
41-
.reduce((list, column) => {
44+
.reduce((list, column, index) => {
4245
const { fixed } = column;
4346
// Convert `fixed='true'` to `fixed='left'` instead
4447
const parsedFixed = fixed === true ? 'left' : fixed;
48+
const mergedKey = `${parentKey}-${index}`;
4549

4650
const subColumns = (column as ColumnGroupType<RecordType>).children;
4751
if (subColumns && subColumns.length > 0) {
4852
return [
4953
...list,
50-
...flatColumns(subColumns).map(subColum => ({
54+
...flatColumns(subColumns, mergedKey).map(subColum => ({
5155
fixed: parsedFixed,
5256
...subColum,
5357
})),
@@ -56,6 +60,7 @@ function flatColumns<RecordType>(columns: ColumnsType<RecordType>): ColumnType<R
5660
return [
5761
...list,
5862
{
63+
key: mergedKey,
5964
...column,
6065
fixed: parsedFixed,
6166
},

src/hooks/useFixedInfo.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,17 @@ export default function useFixedInfo<RecordType>(
77
flattenColumns: readonly ColumnType<RecordType>[],
88
stickyOffsets: StickyOffsets,
99
direction: Direction,
10-
columns: ColumnsType<RecordType>
10+
columns: ColumnsType<RecordType>,
1111
) {
1212
const fixedInfoList = flattenColumns.map((_, colIndex) =>
13-
getCellFixedInfo(colIndex, colIndex, flattenColumns, stickyOffsets, direction, columns?.[colIndex]),
13+
getCellFixedInfo(
14+
colIndex,
15+
colIndex,
16+
flattenColumns,
17+
stickyOffsets,
18+
direction,
19+
columns?.[colIndex],
20+
),
1421
);
1522

1623
return useMemo(

0 commit comments

Comments
 (0)