Skip to content

Commit

Permalink
Merge pull request #1086 from chaishi/develop
Browse files Browse the repository at this point in the history
列宽拖拽调整到边界时无法重新调整;多级表头场景下的列配置,无法全选
  • Loading branch information
honkinglin authored Jul 13, 2022
2 parents 6c75d5a + 956cef4 commit 38d723a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
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

0 comments on commit 38d723a

Please sign in to comment.