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

列宽拖拽调整到边界时无法重新调整;多级表头场景下的列配置,无法全选 #1086

Merged
merged 2 commits into from
Jul 13, 2022
Merged
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
3 changes: 2 additions & 1 deletion src/table/hooks/useColumnController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ export default function useColumnController(props: TdPrimaryTableProps) {

const handleClickAllShowColumns = (checked: boolean, ctx: { e: ChangeEvent<HTMLDivElement> }) => {
if (checked) {
const newData = columns?.map((t) => t.colKey) || [];
const checkboxOptions = getCheckboxOptions(columns);
const newData = checkboxOptions?.map((t) => t.value) || [];
columnCheckboxKeys.current = newData;
props.onColumnChange?.({ type: 'check', columns: newData, e: ctx.e });
} else {
Expand Down
15 changes: 10 additions & 5 deletions src/table/hooks/useColumnResize.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ export default function useColumnResize(tableContentRef: MutableRefObject<HTMLDi
const tableBoundRect = tableContentRef.current?.getBoundingClientRect();
const resizeLinePos = targetBoundRect.right - tableBoundRect.left;
const colLeft = targetBoundRect.left - tableBoundRect.left;
const minColLen = col.resize?.minWidth || DEFAULT_MIN_WIDTH;
const minColWidth = col.resize?.minWidth || DEFAULT_MIN_WIDTH;
const maxColWidth = col.resize?.maxWidth || DEFAULT_MAX_WIDTH;
const minResizeLineLeft = colLeft + minColLen;
const minResizeLineLeft = colLeft + minColWidth;
const maxResizeLineLeft = colLeft + maxColWidth;

// 开始拖拽,记录下鼠标起始位置
Expand Down Expand Up @@ -99,10 +99,15 @@ export default function useColumnResize(tableContentRef: MutableRefObject<HTMLDi
const onDragEnd = () => {
if (resizeLineParams.isDragging) {
// 结束拖拽,更新列宽
const width = parseInt(resizeLineLeft, 10) - colLeft;

let width = Math.ceil(parseInt(resizeLineLeft, 10) - colLeft) || 0;
// 为了避免精度问题,导致 width 宽度超出 [minColWidth, maxColWidth] 的范围,需要对比目标宽度和最小/最大宽度
if (width <= minColWidth) {
width = minColWidth;
} else if (width >= maxColWidth) {
width = maxColWidth;
}
// eslint-disable-next-line
col.width = `${Math.floor(width)}px`;
col.width = `${width}px`;

// 恢复设置
resizeLineParams.isDragging = false;
Expand Down