From 1efe93041bd5203847325c1e547d5c177ac72443 Mon Sep 17 00:00:00 2001 From: chaishi Date: Tue, 16 Aug 2022 22:42:13 +0800 Subject: [PATCH 1/4] fix(table): affixed header 1px --- src/_common | 2 +- src/table/BaseTable.tsx | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/_common b/src/_common index 47eeb106c..63f2bd2ec 160000 --- a/src/_common +++ b/src/_common @@ -1 +1 @@ -Subproject commit 47eeb106c00b813a6808698ae876559eb394cf85 +Subproject commit 63f2bd2eccf0663cc9cf45bab53a1ca4f9d4b4cc diff --git a/src/table/BaseTable.tsx b/src/table/BaseTable.tsx index 4a644d3a4..de2e22a85 100644 --- a/src/table/BaseTable.tsx +++ b/src/table/BaseTable.tsx @@ -219,11 +219,11 @@ const BaseTable = forwardRef((props: TBaseTableProps, ref) => { marginTop: onlyVirtualScrollBordered ? `${borderWidth}px` : 0, }; // 多级表头左边线缺失 - const affixedMultipleHeaderLeftBorder = props.bordered && isMultipleHeader ? 1 : 0; + const affixedLeftBorder = props.bordered ? 1 : 0; const affixedHeader = Boolean(props.headerAffixedTop && tableWidth) && (
@@ -269,7 +269,7 @@ const BaseTable = forwardRef((props: TBaseTableProps, ref) => { >
Date: Wed, 17 Aug 2022 21:34:08 +0800 Subject: [PATCH 2/4] fix(table): refreshTable on resize --- src/table/hooks/useFixed.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/table/hooks/useFixed.ts b/src/table/hooks/useFixed.ts index c9666e3c5..eb94796a0 100644 --- a/src/table/hooks/useFixed.ts +++ b/src/table/hooks/useFixed.ts @@ -1,5 +1,6 @@ import { useEffect, useState, useMemo, useRef, WheelEvent } from 'react'; import get from 'lodash/get'; +import debounce from 'lodash/debounce'; import log from '../../_common/js/log'; import { ClassName, Styles } from '../../common'; import { BaseTableCol, TableRowData, TdBaseTableProps } from '../type'; @@ -295,11 +296,11 @@ export default function useFixed(props: TdBaseTableProps, finalColumns: BaseTabl }; let shadowLastScrollLeft: number; - const updateColumnFixedShadow = (target: HTMLElement) => { + const updateColumnFixedShadow = (target: HTMLElement, extra?: { skipScrollLimit?: boolean }) => { if (!isFixedColumn || !target) return; const { scrollLeft } = target; // 只有左右滚动,需要更新固定列阴影 - if (shadowLastScrollLeft === scrollLeft) return; + if (shadowLastScrollLeft === scrollLeft && (!extra || !extra.skipScrollLimit)) return; shadowLastScrollLeft = scrollLeft; const isShowRight = target.clientWidth + scrollLeft < target.scrollWidth; setShowColumnShadow({ @@ -465,15 +466,15 @@ export default function useFixed(props: TdBaseTableProps, finalColumns: BaseTabl ], ); - const refreshTable = () => { + const refreshTable = debounce(() => { updateTableWidth(); updateFixedHeader(); updateThWidthListHandler(); if (isFixedColumn || isFixedHeader) { updateFixedStatus(); - updateColumnFixedShadow(tableContentRef.current); + updateColumnFixedShadow(tableContentRef.current, { skipScrollLimit: true }); } - }; + }, 30); const onResize = refreshTable; @@ -491,18 +492,17 @@ export default function useFixed(props: TdBaseTableProps, finalColumns: BaseTabl if (columnResizable && recalculateColWidth.current) { recalculateColWidth.current(finalColumns, thWidthList, tableLayout, tableElmWidth); } + const isWatchResize = isFixedColumn || isFixedHeader || !notNeedThWidthList || !data.length; + if (isWatchResize) { + on(window, 'resize', onResize); + } clearTimeout(timer); }); - if (isFixedColumn || isFixedHeader || !notNeedThWidthList) { - on(window, 'resize', onResize); - } return () => { - if (isFixedColumn || isFixedHeader || !notNeedThWidthList) { - off(window, 'resize', onResize); - } + off(window, 'resize', onResize); }; // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); + }, [isFixedColumn]); return { tableWidth, From a04ba3fe23f6d116ec67c229154c933fbbd03253 Mon Sep 17 00:00:00 2001 From: chaishi <974383157@qq.com> Date: Wed, 17 Aug 2022 21:41:16 +0800 Subject: [PATCH 3/4] feat(Table): add some instance functions to BaseTable and PrimaryTable --- src/table/BaseTable.tsx | 1 + src/table/PrimaryTable.tsx | 1 + 2 files changed, 2 insertions(+) diff --git a/src/table/BaseTable.tsx b/src/table/BaseTable.tsx index de2e22a85..b97a20fb8 100644 --- a/src/table/BaseTable.tsx +++ b/src/table/BaseTable.tsx @@ -139,6 +139,7 @@ const BaseTable = forwardRef((props: TBaseTableProps, ref) => { tableHtmlElement: tableElmRef.current, tableContentElement: tableContentRef.current, affixHeaderElement: affixHeaderRef.current, + refreshTable, })); const onFixedChange = () => { diff --git a/src/table/PrimaryTable.tsx b/src/table/PrimaryTable.tsx index 0ff48ce23..9a91d1eec 100644 --- a/src/table/PrimaryTable.tsx +++ b/src/table/PrimaryTable.tsx @@ -79,6 +79,7 @@ const PrimaryTable = forwardRef((props: TPrimaryTableProps, ref) => { validateRowData, validateTableData, clearValidateData, + ...primaryTableRef.current, })); // 1. 影响列数量的因素有:自定义列配置、展开/收起行、多级表头;2. 影响表头内容的因素有:排序图标、筛选图标 From 4a03e749566c6ac1674e4e1de9143cd81672d0ef Mon Sep 17 00:00:00 2001 From: chaishi <974383157@qq.com> Date: Wed, 17 Aug 2022 22:05:33 +0800 Subject: [PATCH 4/4] fix(table): update common --- src/_common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_common b/src/_common index 63f2bd2ec..8179b8d2e 160000 --- a/src/_common +++ b/src/_common @@ -1 +1 @@ -Subproject commit 63f2bd2eccf0663cc9cf45bab53a1ca4f9d4b4cc +Subproject commit 8179b8d2e12a34e55c4e9ee0ce4170f842eacf1f