Skip to content

Commit 6e85fd9

Browse files
committed
perf: table
1 parent d3acab2 commit 6e85fd9

File tree

17 files changed

+119
-94
lines changed

17 files changed

+119
-94
lines changed

components/legacy-table/src/TableRow.jsx

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import PropTypes, { withUndefined } from '../../_util/vue-types';
33
import TableCell from './TableCell';
44
import { initDefaultProps, findDOMNode } from '../../_util/props-util';
55
import BaseMixin from '../../_util/BaseMixin';
6-
import warning from '../../_util/warning';
76
import { computed, inject } from 'vue';
87
function noop() {}
98
const TableRow = {

components/table/Table.tsx

+17-9
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,17 @@ import defaultLocale from '../locale/en_US';
3535
import type { SizeType } from '../config-provider';
3636
import devWarning from '../vc-util/devWarning';
3737
import type { PropType } from 'vue';
38-
import { computed, defineComponent, ref, toRef, watchEffect } from 'vue';
38+
import { reactive } from 'vue';
39+
import { computed, defineComponent, toRef, watchEffect } from 'vue';
3940
import type { DefaultRecordType } from '../vc-table/interface';
4041
import useBreakpoint from '../_util/hooks/useBreakpoint';
4142
import useConfigInject from '../_util/hooks/useConfigInject';
4243
import { useLocaleReceiver } from '../locale-provider/LocaleReceiver';
4344
import classNames from '../_util/classNames';
4445
import omit from '../_util/omit';
4546
import { initDefaultProps } from '../_util/props-util';
46-
import { ContextSlots, useProvideSlots } from './context';
47+
import { useProvideSlots } from './context';
48+
import type { ContextSlots } from './context';
4749
import useColumns from './hooks/useColumns';
4850
import { convertChildrenToColumns } from './util';
4951

@@ -77,6 +79,7 @@ export interface TableProps<RecordType = DefaultRecordType>
7779
| 'scroll'
7880
| 'emptyText'
7981
| 'canExpandable'
82+
| 'onUpdateInternalRefs'
8083
> {
8184
dropdownPrefixCls?: string;
8285
dataSource?: RcTableProps<RecordType>['data'];
@@ -217,11 +220,11 @@ const InteralTable = defineComponent<
217220
}
218221
>({
219222
name: 'InteralTable',
223+
inheritAttrs: false,
220224
props: initDefaultProps(tableProps(), {
221225
rowKey: 'key',
222226
}) as any,
223-
inheritAttrs: false,
224-
emits: [],
227+
// emits: ['expandedRowsChange', 'change', 'expand'],
225228
slots: [
226229
'emptyText',
227230
'expandIcon',
@@ -282,8 +285,12 @@ const InteralTable = defineComponent<
282285
return null;
283286
});
284287

285-
const internalRefs = {
286-
body: ref<HTMLDivElement>(),
288+
const internalRefs = reactive({
289+
body: null,
290+
});
291+
292+
const updateInternalRefs = refs => {
293+
Object.assign(internalRefs, refs);
287294
};
288295

289296
// ============================ RowKey ============================
@@ -325,9 +332,9 @@ const InteralTable = defineComponent<
325332
}
326333
}
327334

328-
if (scroll && scroll.scrollToFirstRowOnChange !== false && internalRefs.body.value) {
335+
if (scroll && scroll.scrollToFirstRowOnChange !== false && internalRefs.body) {
329336
scrollTo(0, {
330-
getContainer: () => internalRefs.body.value!,
337+
getContainer: () => internalRefs.body,
331338
});
332339
}
333340

@@ -606,7 +613,8 @@ const InteralTable = defineComponent<
606613
rowClassName={internalRowClassName}
607614
// Internal
608615
internalHooks={INTERNAL_HOOKS}
609-
internalRefs={internalRefs as any}
616+
internalRefs={internalRefs}
617+
onUpdateInternalRefs={updateInternalRefs}
610618
transformColumns={transformColumns}
611619
v-slots={{
612620
...slots,

components/table/demo/fixed-columns.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ To fix some columns and scroll inside other columns, and you must set `scroll.x`
2525
</docs>
2626

2727
<template>
28-
<a-table :columns="columns" :data-source="data" :scroll="{ x: 1300 }">
28+
<a-table :columns="columns" :data-source="data" :scroll="{ x: 1300, y: 1000 }">
2929
<template #bodyCell="{ column, text }">
3030
<template v-if="column.key === 'operation'">
3131
<a>action</a>

components/table/demo/summary.vue

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Set summary content by `summary` prop. Sync column fixed status with `a-table-su
3838
</a-table-summary-row>
3939
</template>
4040
</a-table>
41+
<br />
4142
<a-table
4243
:columns="fixedColumns"
4344
:data-source="fixedData"

components/table/hooks/useColumns.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import devWarning from '../../vc-util/devWarning';
22
import type { Ref } from 'vue';
3-
import { ContextSlots } from '../context';
3+
import type { ContextSlots } from '../context';
44
import type { TransformColumns, ColumnsType } from '../interface';
55

66
function fillSlots<RecordType>(columns: ColumnsType<RecordType>, contextSlots: Ref<ContextSlots>) {

components/table/index.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import Table, { tableProps } from './Table';
22
import Column from './Column';
33
import ColumnGroup from './ColumnGroup';
44
import type { TableProps, TablePaginationConfig } from './Table';
5-
import { App, defineComponent } from 'vue';
5+
import { defineComponent } from 'vue';
6+
import type { App } from 'vue';
67
import { Summary, SummaryCell, SummaryRow } from '../vc-table';
78
import { SELECTION_ALL, SELECTION_INVERT, SELECTION_NONE } from './hooks/useSelection';
89

components/vc-table/Body/BodyRow.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ export interface BodyRowProps<RecordType> {
2424
}
2525

2626
export default defineComponent<BodyRowProps<unknown>>({
27+
name: 'BodyRow',
28+
inheritAttrs: false,
2729
props: [
2830
'record',
2931
'index',
@@ -38,8 +40,6 @@ export default defineComponent<BodyRowProps<unknown>>({
3840
'getRowKey',
3941
'childrenColumnName',
4042
] as any,
41-
name: 'BodyRow',
42-
inheritAttrs: false,
4343
setup(props, { attrs }) {
4444
const tableContext = useInjectTable();
4545
const bodyContext = useInjectBody();
@@ -92,6 +92,7 @@ export default defineComponent<BodyRowProps<unknown>>({
9292
} else if (typeof rowClassName === 'function') {
9393
return rowClassName(record, index, indent);
9494
}
95+
return '';
9596
});
9697

9798
const columnsKey = computed(() => getColumnsKey(bodyContext.flattenColumns));

components/vc-table/Body/ExpandedRow.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface ExpandedRowProps {
1717

1818
export default defineComponent<ExpandedRowProps>({
1919
name: 'ExpandedRow',
20+
inheritAttrs: false,
2021
props: [
2122
'prefixCls',
2223
'component',
@@ -28,7 +29,6 @@ export default defineComponent<ExpandedRowProps>({
2829
'expanded',
2930
'colSpan',
3031
] as any,
31-
inheritAttrs: false,
3232
setup(props, { slots, attrs }) {
3333
const tableContext = useInjectTable();
3434
return () => {
+26-13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { defineComponent, onMounted, ref } from 'vue';
12
import VCResizeObserver from '../../vc-resize-observer';
23
import type { Key } from '../interface';
34

@@ -6,16 +7,28 @@ export interface MeasureCellProps {
67
onColumnResize: (key: Key, width: number) => void;
78
}
89

9-
export default function MeasureCell({ columnKey }: MeasureCellProps, { emit }) {
10-
return (
11-
<VCResizeObserver
12-
onResize={({ offsetWidth }) => {
13-
emit('columnResize', columnKey, offsetWidth);
14-
}}
15-
>
16-
<td style={{ padding: 0, border: 0, height: 0 }}>
17-
<div style={{ height: 0, overflow: 'hidden' }}>&nbsp;</div>
18-
</td>
19-
</VCResizeObserver>
20-
);
21-
}
10+
export default defineComponent<MeasureCellProps>({
11+
name: 'MeasureCell',
12+
props: ['columnKey'] as any,
13+
setup(props, { emit }) {
14+
const tdRef = ref();
15+
onMounted(() => {
16+
if (tdRef.value) {
17+
emit('columnResize', props.columnKey, tdRef.value.offsetWidth);
18+
}
19+
});
20+
return () => {
21+
return (
22+
<VCResizeObserver
23+
onResize={({ offsetWidth }) => {
24+
emit('columnResize', props.columnKey, offsetWidth);
25+
}}
26+
>
27+
<td ref={tdRef} style={{ padding: 0, border: 0, height: 0 }}>
28+
<div style={{ height: 0, overflow: 'hidden' }}>&nbsp;</div>
29+
</td>
30+
</VCResizeObserver>
31+
);
32+
};
33+
},
34+
});

components/vc-table/Body/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export default defineComponent<BodyProps<any>>({
107107
const columnsKey = getColumnsKey(flattenColumns);
108108

109109
return (
110-
<WrapperComponent className={`${prefixCls}-tbody`}>
110+
<WrapperComponent class={`${prefixCls}-tbody`}>
111111
{/* Measure body column width with additional hidden col */}
112112
{measureColumnWidth && (
113113
<tr

components/vc-table/FixedHolder/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export interface FixedHeaderProps<RecordType> extends HeaderProps<RecordType> {
4848

4949
export default defineComponent<FixedHeaderProps<DefaultRecordType>>({
5050
name: 'FixedHolder',
51+
inheritAttrs: false,
5152
props: [
5253
'columns',
5354
'flattenColumns',
@@ -64,7 +65,6 @@ export default defineComponent<FixedHeaderProps<DefaultRecordType>>({
6465
'stickyClassName',
6566
] as any,
6667
emits: ['scroll'],
67-
inheritAttrs: false,
6868
setup(props, { attrs, slots, emit }) {
6969
const tableContext = useInjectTable();
7070
const combinationScrollBarSize = computed(() =>

components/vc-table/Footer/Cell.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export interface SummaryCellProps {
1414

1515
export default defineComponent<SummaryCellProps>({
1616
name: 'SummaryCell',
17-
props: ['index', 'colSpan', 'rowSpan', 'align'] as any,
1817
inheritAttrs: false,
18+
props: ['index', 'colSpan', 'rowSpan', 'align'] as any,
1919
setup(props, { attrs, slots }) {
2020
const tableContext = useInjectTable();
2121
const summaryContext = useInjectSummary();

components/vc-table/Footer/Summary.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ export interface SummaryProps {
77

88
let indexGuid = 0;
99
const Summary = defineComponent<SummaryProps>({
10-
props: ['fixed'] as any,
1110
name: 'Summary',
11+
props: ['fixed'] as any,
1212
setup(props, { slots }) {
1313
const tableContext = useInjectTable();
1414
const uniKey = `table-summary-uni-key-${++indexGuid}`;

components/vc-table/Footer/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export interface FooterProps<RecordType = DefaultRecordType> {
1414

1515
export default defineComponent({
1616
name: 'Footer',
17-
props: ['stickyOffsets', 'flattenColumns'],
1817
inheritAttrs: false,
18+
props: ['stickyOffsets', 'flattenColumns'],
1919
setup(props, { slots }) {
2020
const tableContext = useInjectTable();
2121
useProvideSummary(

0 commit comments

Comments
 (0)