Skip to content

Commit 278a471

Browse files
committed
chore: tmp of columns
1 parent e2453e8 commit 278a471

File tree

5 files changed

+39
-17
lines changed

5 files changed

+39
-17
lines changed

docs/examples/virtual.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,15 @@ const columns: ColumnsType = [
160160
},
161161
];
162162

163+
function cleanOnCell(cols: any = []) {
164+
cols.forEach(col => {
165+
delete (col as any).onCell;
166+
167+
cleanOnCell((col as any).children);
168+
});
169+
}
170+
cleanOnCell(columns);
171+
163172
const data: RecordType[] = new Array(4 * 10000).fill(null).map((_, index) => ({
164173
a: `a${index}`,
165174
b: `b${index}`,
@@ -192,7 +201,10 @@ const Demo = () => {
192201
scroll={{ x: 1200, y: scrollY ? 200 : null }}
193202
data={data}
194203
rowKey="indexKey"
195-
expandable={{}}
204+
expandable={{
205+
expandedRowRender: () => 2333,
206+
columnWidth: 60,
207+
}}
196208
/>
197209
</div>
198210
);

src/Body/BodyRow.tsx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { useContext } from '@rc-component/context';
21
import classNames from 'classnames';
32
import * as React from 'react';
43
import Cell from '../Cell';
5-
import TableContext, { responseImmutable } from '../context/TableContext';
4+
import { responseImmutable } from '../context/TableContext';
65
import devRenderTimes from '../hooks/useRenderTimes';
76
import type { ColumnType, CustomizeComponent, GetComponentProps, GetRowKey } from '../interface';
87
import ExpandedRow from './ExpandedRow';
@@ -110,20 +109,18 @@ function BodyRow<RecordType extends { children?: readonly RecordType[] }>(
110109
const {
111110
prefixCls,
112111
flattenColumns,
113-
expandableType,
114112
expandRowByClick,
115113
onTriggerExpand,
116114
rowClassName,
117115
expandedRowClassName,
118116
expandedRowRender,
119117

120118
// Misc
121-
nestExpandable,
122119
expanded,
120+
supportExpand,
121+
expandable,
123122
} = rowInfo;
124123

125-
const { rowExpandable } = useContext(TableContext, ['rowExpandable']);
126-
127124
const [expandRended, setExpandRended] = React.useState(false);
128125

129126
if (process.env.NODE_ENV !== 'production') {
@@ -136,14 +133,11 @@ function BodyRow<RecordType extends { children?: readonly RecordType[] }>(
136133
}
137134
}, [expanded]);
138135

139-
const rowSupportExpand = expandableType === 'row' && (!rowExpandable || rowExpandable(record));
140-
const mergedExpandable = rowSupportExpand || nestExpandable;
141-
142136
// =========================== onRow ===========================
143137
const additionalProps = onRow?.(record, index);
144138

145139
const onClick: React.MouseEventHandler<HTMLElement> = (event, ...args) => {
146-
if (expandRowByClick && mergedExpandable) {
140+
if (expandRowByClick && expandable) {
147141
onTriggerExpand(record, event);
148142
}
149143

@@ -212,7 +206,7 @@ function BodyRow<RecordType extends { children?: readonly RecordType[] }>(
212206

213207
// ======================== Expand Row =========================
214208
let expandRowNode: React.ReactElement;
215-
if (rowSupportExpand && (expandRended || expanded)) {
209+
if (supportExpand && (expandRended || expanded)) {
216210
const expandContent = expandedRowRender(record, index, indent + 1, expanded);
217211
const computedExpandedRowClassName =
218212
expandedRowClassName && expandedRowClassName(record, index, indent);

src/StaticTable/BodyGrid.tsx

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

5455
React.useEffect(() => {
5556
columnsWidth.forEach(([key, width]) => {

src/StaticTable/BodyLine.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ const BodyLine = React.forwardRef<HTMLDivElement, BodyLineProps>((props, ref) =>
3434
const rowInfo = useRowInfo(record, rowKey);
3535

3636
// ========================== Expand ==========================
37-
const rowSupportExpand = expandableType === 'row' && (!rowExpandable || rowExpandable(record));
3837

3938
// ========================== Render ==========================
4039

src/hooks/useRowInfo.tsx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export default function useRowInfo<RecordType>(
2929
expanded: boolean;
3030
hasNestChildren: boolean;
3131
record: RecordType;
32+
supportExpand: boolean;
33+
expandable: boolean;
3234
} {
3335
const context: TableContextProps = useContext(TableContext, [
3436
'prefixCls',
@@ -45,22 +47,34 @@ export default function useRowInfo<RecordType>(
4547
'expandIconColumnIndex',
4648
'expandedKeys',
4749
'childrenColumnName',
50+
'rowExpandable',
4851
]);
4952

50-
const { flattenColumns, expandableType, expandedKeys, childrenColumnName, onTriggerExpand } =
51-
context;
52-
53-
const columnsKey = getColumnsKey(flattenColumns);
53+
const {
54+
flattenColumns,
55+
expandableType,
56+
expandedKeys,
57+
childrenColumnName,
58+
onTriggerExpand,
59+
rowExpandable,
60+
} = context;
5461

62+
// ======================= Expandable =======================
5563
// Only when row is not expandable and `children` exist in record
5664
const nestExpandable = expandableType === 'nest';
5765

66+
const rowSupportExpand = expandableType === 'row' && (!rowExpandable || rowExpandable(record));
67+
const mergedExpandable = rowSupportExpand || nestExpandable;
68+
5869
const expanded = expandedKeys && expandedKeys.has(rowKey);
5970

6071
const hasNestChildren = childrenColumnName && record && record[childrenColumnName];
6172

6273
const onInternalTriggerExpand = useEvent(onTriggerExpand);
6374

75+
// ========================= Column =========================
76+
const columnsKey = getColumnsKey(flattenColumns);
77+
6478
return {
6579
...context,
6680
columnsKey,
@@ -69,5 +83,7 @@ export default function useRowInfo<RecordType>(
6983
hasNestChildren,
7084
record,
7185
onTriggerExpand: onInternalTriggerExpand,
86+
supportExpand: rowSupportExpand,
87+
expandable: mergedExpandable,
7288
};
7389
}

0 commit comments

Comments
 (0)