Skip to content

Commit d9580a0

Browse files
committed
渲染复用功能实现
1 parent 61d3dff commit d9580a0

File tree

2 files changed

+80
-32
lines changed

2 files changed

+80
-32
lines changed

packages/ve-table/src/body/index.jsx

Lines changed: 65 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ export default {
167167
colsWidthsEfficientCount: 0,
168168
// has init columns widths 此属性可优化固定列表格初始化渲染慢问题
169169
hasPreparedColsWidths: false,
170+
// virtual scroll preview rendered rowKey
171+
virtualScrollPreviewRenderedRowKeys: [],
172+
// virtual scroll repeat rendered rowKey
173+
virtualScrollRepeatRenderedRowKeys: [],
170174
},
171175
computed: {
172176
/*
@@ -810,6 +814,21 @@ export default {
810814
}
811815
return result;
812816
},
817+
818+
// rendering row keys
819+
renderingRowKeys(rowKeys) {
820+
const {
821+
virtualScrollPreviewRenderedRowKeys: previewRenderedRowKeys,
822+
} = this.$options.customOption;
823+
824+
this.$options.customOption.virtualScrollRepeatRenderedRowKeys =
825+
rowKeys.filter((rowKey) => {
826+
return previewRenderedRowKeys.indexOf(rowKey) != -1;
827+
});
828+
829+
this.$options.customOption.virtualScrollPreviewRenderedRowKeys =
830+
rowKeys;
831+
},
813832
},
814833
mounted() {
815834
// receive checkbox row selected change from VE_TABLE_BODY_CHECKBOX_CONTENT
@@ -866,6 +885,9 @@ export default {
866885
isScrolling,
867886
} = this;
868887

888+
const { virtualScrollRepeatRenderedRowKeys } =
889+
this.$options.customOption;
890+
869891
return (
870892
<tbody>
871893
{/* Measure each column width with additional hidden col */}
@@ -893,6 +915,37 @@ export default {
893915
})}
894916
</tr>
895917
{actualRenderTableData.map((rowData, rowIndex) => {
918+
const trProps = {
919+
key: this.getTrKey({ rowData, rowIndex }),
920+
props: {
921+
rowIndex,
922+
rowData,
923+
colgroups,
924+
expandOption,
925+
expandedRowkeys,
926+
checkboxOption,
927+
radioOption,
928+
rowKeyFieldName,
929+
expandRowChange,
930+
internalCheckboxSelectedRowKeys,
931+
internalRadioSelectedRowKey,
932+
isVirtualScroll,
933+
isExpandRow: isExpandRow({
934+
rowData,
935+
rowIndex,
936+
}),
937+
cellStyleOption,
938+
cellSpanOption: this.cellSpanOption,
939+
highlightRowKey: this.highlightRowKey,
940+
eventCustomOption: this.eventCustomOption,
941+
cellSelectionKeyData: this.cellSelectionKeyData,
942+
editOption: this.editOption,
943+
editingCells: this.editingCells,
944+
editingFocusCell: this.editingFocusCell,
945+
columnCollection: this.columnCollection,
946+
},
947+
};
948+
896949
if (isScrolling) {
897950
const trPropsScrolling = {
898951
key: this.getTrKey({ rowData, rowIndex }),
@@ -901,39 +954,19 @@ export default {
901954
},
902955
};
903956

904-
return <BodyTrScrolling {...trPropsScrolling} />;
957+
if (
958+
virtualScrollRepeatRenderedRowKeys.indexOf(
959+
rowData[this.rowKeyFieldName],
960+
) != -1
961+
) {
962+
return [
963+
// body tr
964+
<BodyTr {...trProps} />,
965+
];
966+
} else {
967+
return <BodyTrScrolling {...trPropsScrolling} />;
968+
}
905969
} else {
906-
const trProps = {
907-
key: this.getTrKey({ rowData, rowIndex }),
908-
props: {
909-
rowIndex,
910-
rowData,
911-
colgroups,
912-
expandOption,
913-
expandedRowkeys,
914-
checkboxOption,
915-
radioOption,
916-
rowKeyFieldName,
917-
expandRowChange,
918-
internalCheckboxSelectedRowKeys,
919-
internalRadioSelectedRowKey,
920-
isVirtualScroll,
921-
isExpandRow: isExpandRow({
922-
rowData,
923-
rowIndex,
924-
}),
925-
cellStyleOption,
926-
cellSpanOption: this.cellSpanOption,
927-
highlightRowKey: this.highlightRowKey,
928-
eventCustomOption: this.eventCustomOption,
929-
cellSelectionKeyData: this.cellSelectionKeyData,
930-
editOption: this.editOption,
931-
editingCells: this.editingCells,
932-
editingFocusCell: this.editingFocusCell,
933-
columnCollection: this.columnCollection,
934-
},
935-
};
936-
937970
return [
938971
// body tr
939972
<BodyTr {...trProps} />,

packages/ve-table/src/index.jsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ export default {
189189
*/
190190
columnsOptionResetTime: 0,
191191
tableContainerRef: "tableContainerRef",
192+
tableBodyRef: "tableBodyRef",
192193
tableContentRef: "tableContentRef",
193194
virtualPhantomRef: "virtualPhantomRef",
194195
cloneColumns: [],
@@ -1046,6 +1047,19 @@ export default {
10461047
//此时的偏移量
10471048
this.setVirtualScrollStartOffset();
10481049

1050+
if (!this.isScrolling) {
1051+
const bodyElement = this.$refs[this.tableBodyRef];
1052+
1053+
if (bodyElement) {
1054+
bodyElement.renderingRowKeys(
1055+
this.allRowKeys.slice(
1056+
visibleStartIndex,
1057+
visibleEndIndex + 1,
1058+
),
1059+
);
1060+
}
1061+
}
1062+
10491063
const { scrolling } = virtualScrollOption;
10501064
if (isFunction(scrolling)) {
10511065
const visibleAboveCount = this.getVirtualScrollAboveCount();
@@ -1734,6 +1748,7 @@ export default {
17341748

17351749
// body props
17361750
const bodyProps = {
1751+
ref: this.tableBodyRef,
17371752
class: [clsName("body"), this.tableBodyClass],
17381753
props: {
17391754
tableViewportWidth,

0 commit comments

Comments
 (0)