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

[Table] fix sibling column resizable does not work #2335

Merged
merged 6 commits into from
Apr 20, 2023
20 changes: 14 additions & 6 deletions src/table/hooks/useColumnResize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,20 @@ export default function useColumnResize(params: {
};
};

const getFixedToLeftResizeInfo = (targetBoundRect: DOMRect, tableBoundRect: DOMRect) => {
const resizeLinePos = targetBoundRect.left - tableBoundRect.left;
const getFixedToLeftResizeInfo = (
target: HTMLElement,
col: BaseTableCol,
targetBoundRect: DOMRect,
tableBoundRect: DOMRect,
) => {
const targetIsSameAsCol = target.dataset.colkey === col.colKey;
const colLeft = targetBoundRect.left - tableBoundRect.left;
const resizeLinePos = colLeft + targetBoundRect.width;
const { minColWidth, maxColWidth } = getMinMaxColWidth(col);
return {
resizeLinePos,
minResizeLineLeft: colLeft,
maxResizeLineLeft: colLeft,
minResizeLineLeft: colLeft + (targetIsSameAsCol ? minColWidth : targetBoundRect.width),
maxResizeLineLeft: colLeft + (targetIsSameAsCol ? maxColWidth : targetBoundRect.width),
};
};

Expand All @@ -218,13 +225,14 @@ export default function useColumnResize(params: {
return !(isWidthAbnormal || isWidthOverflow.value || index === leafColumns.value.length - 1);
};
const getOtherResizeInfo = (
target: HTMLElement,
col: BaseTableCol<TableRowData>,
effectPrevCol: BaseTableCol,
targetBoundRect: DOMRect,
tableBoundRect: DOMRect,
) => effectPrevCol
? getNormalResizeInfo(col, effectPrevCol, targetBoundRect, tableBoundRect)
: getFixedToLeftResizeInfo(targetBoundRect, tableBoundRect);
: getFixedToLeftResizeInfo(target, col, targetBoundRect, tableBoundRect);

// 调整表格列宽
const onColumnMousedown = (e: MouseEvent, col: BaseTableCol<TableRowData>, index: number) => {
Expand All @@ -236,7 +244,7 @@ export default function useColumnResize(params: {
const effectPrevCol = effectColMap.value[col.colKey]?.prev;
const { resizeLinePos, minResizeLineLeft, maxResizeLineLeft } = isColRightFixActive(col)
? getFixedToRightResizeInfo(target, col, effectNextCol, targetBoundRect, tableBoundRect)
: getOtherResizeInfo(col, effectNextCol, targetBoundRect, tableBoundRect);
: getOtherResizeInfo(target, col, effectPrevCol, targetBoundRect, tableBoundRect);

// 开始拖拽,记录下鼠标起始位置
resizeLineParams.isDragging = true;
Expand Down