Skip to content

Commit 07afed4

Browse files
committed
demo: update
1 parent b0819e4 commit 07afed4

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

docs/examples/virtual.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ interface RecordType {
1111
indexKey: string;
1212
}
1313

14-
const columns: ColumnsType = [
14+
const defaultColumns: ColumnsType = [
1515
// { title: 'title1', dataIndex: 'a', key: 'a', width: 100,},
1616
// { title: 'title1', dataIndex: 'a', key: 'a', width: 100, },
1717
{ title: 'title1', dataIndex: 'a', key: 'a', width: 100, fixed: 'left' },
@@ -183,16 +183,13 @@ const Demo = () => {
183183
const tblRef = React.useRef<Reference>();
184184
const [enableColRowSpan, setEnableColRowSpan] = useState(false);
185185

186-
function cleanOnCell(cols: any = []) {
187-
cols.forEach(col => {
188-
delete (col as any).onCell;
189-
190-
cleanOnCell((col as any).children);
186+
function cleanOnCell(cols: ColumnsType) {
187+
return cols?.map(({ onCell, ...col }: any) => {
188+
return { ...col, children: cleanOnCell(col.children) };
191189
});
192190
}
193-
if (!enableColRowSpan) {
194-
cleanOnCell(columns);
195-
}
191+
192+
const columns = enableColRowSpan ? defaultColumns : cleanOnCell(defaultColumns);
196193

197194
return (
198195
<div style={{ width: 800, padding: `0 64px` }}>
@@ -220,6 +217,7 @@ const Demo = () => {
220217
</button>
221218

222219
<VirtualTable
220+
virtual={{ x: true }}
223221
columns={columns}
224222
// expandedRowRender={({ b, c }) => b || c}
225223
scroll={{ x: 1300, y: 200 }}

src/Table.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ function Table<RecordType extends DefaultRecordType>(
427427
target(scrollLeft);
428428
} else if (target.scrollLeft !== scrollLeft) {
429429
target.scrollLeft = scrollLeft;
430+
430431
// Delay to force scroll position if not sync
431432
// ref: https://github.com/ant-design/ant-design/issues/37179
432433
if (target.scrollLeft !== scrollLeft) {
@@ -446,6 +447,7 @@ function Table<RecordType extends DefaultRecordType>(
446447
const compareTarget = currentTarget || EMPTY_SCROLL_TARGET;
447448
if (!getScrollTarget() || getScrollTarget() === compareTarget) {
448449
setScrollTarget(compareTarget);
450+
449451
forceScroll(mergedScrollLeft, scrollHeaderRef.current);
450452
forceScroll(mergedScrollLeft, scrollBodyRef.current);
451453
forceScroll(mergedScrollLeft, scrollSummaryRef.current);

src/VirtualTable/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function VirtualTable<RecordType>(props: VirtualTableProps<RecordType>, ref: Rea
104104
}
105105

106106
export type ForwardGenericVirtualTable = (<RecordType>(
107-
props: TableProps<RecordType> & React.RefAttributes<Reference>,
107+
props: VirtualTableProps<RecordType> & React.RefAttributes<Reference>,
108108
) => React.ReactElement) & { displayName?: string };
109109

110110
const RefVirtualTable = React.forwardRef(VirtualTable) as ForwardGenericVirtualTable;

0 commit comments

Comments
 (0)