Skip to content

Commit

Permalink
fix(table): update top and bottom affix position when resize (#1570)
Browse files Browse the repository at this point in the history
  • Loading branch information
uyarn committed Sep 27, 2022
1 parent f9ca7cc commit c9ead08
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
19 changes: 16 additions & 3 deletions src/table/base-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ export default defineComponent({
const tableElmRef = ref<HTMLTableElement>();
const tableBodyRef = ref<HTMLTableElement>();
const tableFootHeight = ref(0);
const paginationAffixRef = ref();
const horizontalScrollAffixRef = ref();

const {
virtualScrollClasses, tableLayoutClasses, tableBaseClass, tableColFixedClasses,
Expand All @@ -69,6 +67,12 @@ export default defineComponent({
const { isMultipleHeader, spansAndLeafNodes, thList } = useTableHeader(props);
const finalColumns = computed(() => spansAndLeafNodes.value?.leafColumns || props.columns);

// 吸附相关ref 用来做视图resize后重新定位
const paginationAffixRef = ref();
const horizontalScrollAffixRef = ref();
const headerTopAffixRef = ref();
const footerBottomAffixRef = ref();

// 固定表头和固定列逻辑
const {
scrollbarWidth,
Expand All @@ -90,7 +94,12 @@ export default defineComponent({
updateThWidthList,
setRecalculateColWidthFuncRef,
addTableResizeObserver,
} = useFixed(props, context, finalColumns, paginationAffixRef, horizontalScrollAffixRef);
} = useFixed(props, context, finalColumns, {
paginationAffixRef,
horizontalScrollAffixRef,
headerTopAffixRef,
footerBottomAffixRef,
});

// 1. 表头吸顶;2. 表尾吸底;3. 底部滚动条吸底;4. 分页器吸底
const {
Expand Down Expand Up @@ -315,6 +324,8 @@ export default defineComponent({
onInnerVirtualScroll,
paginationAffixRef,
horizontalScrollAffixRef,
headerTopAffixRef,
footerBottomAffixRef,
};
},

Expand Down Expand Up @@ -415,6 +426,7 @@ export default defineComponent({
offsetBottom={marginScrollbarWidth || 0}
props={getAffixProps(this.footerAffixedBottom, this.footerAffixProps)}
style={{ marginTop: `${-1 * (this.tableFootHeight + marginScrollbarWidth)}px` }}
ref="footerBottomAffixRef"
>
<div
ref="affixFooterRef"
Expand Down Expand Up @@ -459,6 +471,7 @@ export default defineComponent({
offsetTop={0}
props={getAffixProps(this.headerAffixedTop, this.headerAffixProps)}
onFixedChange={this.onFixedChange}
ref="headerTopAffixRef"
>
{this.renderFixedHeader(columns)}
</Affix>
Expand Down
9 changes: 5 additions & 4 deletions src/table/hooks/useFixed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ export default function useFixed(
props: TdBaseTableProps,
context: SetupContext,
finalColumns: ComputedRef<BaseTableCol<TableRowData>[]>,
paginationAffixRef: Ref,
horizontalScrollAffixRef: Ref,
affixRef: Record<string, Ref>,
) {
const {
columns,
Expand Down Expand Up @@ -381,8 +380,10 @@ export default function useFixed(

const updateAffixPosition = () => {
// 在表格高度变化的时候 需要手动调整affix的位置 因为affix本身无法监听到这些变化触发重新计算
paginationAffixRef.value?.handleScroll?.();
horizontalScrollAffixRef.value?.handleScroll?.();
affixRef.paginationAffixRef.value?.handleScroll?.();
affixRef.horizontalScrollAffixRef.value?.handleScroll?.();
affixRef.headerTopAffixRef.value?.handleScroll?.();
affixRef.footerBottomAffixRef.value?.handleScroll?.();
};

const updateThWidthList = (trList: HTMLCollection | { [colKey: string]: number }) => {
Expand Down
1 change: 1 addition & 0 deletions src/upload/themes/style/css.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '../../style/index.css';
1 change: 1 addition & 0 deletions src/upload/themes/style/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '../../style/index.js';

0 comments on commit c9ead08

Please sign in to comment.