Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix($table): synchronize the colspan state of the table component #2237

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 4 additions & 15 deletions src/table/hooks/useRowspanAndColspan.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useEffect, useState } from 'react';
import get from 'lodash/get';
import log from '../../_common/js/log';
import { BaseTableCellParams, BaseTableCol, TableRowData, TableRowspanAndColspanFunc } from '../type';
Expand All @@ -23,7 +22,7 @@ export default function useRowspanAndColspan(
rowKey: string,
rowspanAndColspan: TableRowspanAndColspanFunc<TableRowData>,
) {
const [skipSpansMap] = useState(new Map<string, SkipSpansValue>());
const skipSpansMap = new Map<string, SkipSpansValue>();

// 计算单元格是否跳过渲染
const onTrRowspanOrColspan = (params: BaseTableCellParams<TableRowData>, skipSpansValue: SkipSpansValue) => {
Expand All @@ -45,12 +44,7 @@ export default function useRowspanAndColspan(
};

// 计算单元格是否需要设置 rowspan 和 colspan
const updateSkipSpansMap = (
data: TableRowData[],
columns: BaseTableCol<TableRowData>[],
rowspanAndColspan: TableRowspanAndColspanFunc<TableRowData>,
) => {
skipSpansMap.clear();
(() => {
if (!data || !rowspanAndColspan) return;
for (let i = 0, len = data.length; i < len; i++) {
const row = data[i];
Expand All @@ -73,12 +67,7 @@ export default function useRowspanAndColspan(
onTrRowspanOrColspan?.(params, state);
}
}
};

useEffect(() => {
updateSkipSpansMap(data, columns, rowspanAndColspan);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [data, columns, rowspanAndColspan]);
})();

return { skipSpansMap, updateSkipSpansMap };
return { skipSpansMap };
}
Loading