Skip to content

Commit

Permalink
fix(table): fix fixed resize problem (#2598)
Browse files Browse the repository at this point in the history
  • Loading branch information
flsion authored Jul 28, 2023
1 parent 78ddc1b commit 5153fce
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions packages/web-vue/components/table/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ export interface TableColumnData {
rowSpan?: number;
index?: number;
parent?: TableColumnData;
_resizeWidth?: number;
}

export interface TableBorder {
Expand Down
16 changes: 9 additions & 7 deletions packages/web-vue/components/table/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -760,12 +760,18 @@ export default defineComponent({
const dataColumns = ref<TableColumnData[]>([]);
const groupColumns = ref<TableColumnData[][]>([]);

const { resizingColumn, columnWidth, handleThMouseDown } = useColumnResize(
thRefs,
emit
);

watch(
[columns, slotColumns],
[columns, slotColumns, columnWidth],
([columns, slotColumns]) => {
const result = getGroupColumns(
slotColumns ?? columns ?? [],
dataColumnMap
dataColumnMap,
columnWidth
);
dataColumns.value = result.dataColumns;
groupColumns.value = result.groupColumns;
Expand Down Expand Up @@ -994,11 +1000,6 @@ export default defineComponent({
handleDrop,
} = useDrag(draggable);

const { resizingColumn, columnWidth, handleThMouseDown } = useColumnResize(
thRefs,
emit
);

const processedData = computed(() => {
const travel = (data: TableData[]) => {
const result: TableDataWithRaw[] = [];
Expand Down Expand Up @@ -1998,6 +1999,7 @@ export default defineComponent({
column={column}
operations={operations.value}
dataColumns={dataColumns.value}
columnWidth={columnWidth}
resizable={resizable}
onClick={(ev: Event) => handleHeaderClick(column, ev)}
/>
Expand Down
9 changes: 7 additions & 2 deletions packages/web-vue/components/table/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ const setParentFixed = (column: TableColumnData, fixed: 'left' | 'right') => {
// Get the grouped header row data
export const getGroupColumns = (
columns: TableColumnData[],
columnMap: Map<string, TableColumnData>
columnMap: Map<string, TableColumnData>,
columnWidth: Record<string, number>
) => {
const totalHeaderRows = getTotalHeaderRows(columns);

Expand Down Expand Up @@ -124,6 +125,10 @@ export const getGroupColumns = (
cell.dataIndex = `__arco_data_index_${dataColumns.length}`;
}

if (columnWidth[cell.dataIndex]) {
cell._resizeWidth = columnWidth[cell.dataIndex];
}

// dataColumns和groupColumns公用一个cell的引用
columnMap.set(cell.dataIndex, cell);
dataColumns.push(cell);
Expand Down Expand Up @@ -209,7 +214,7 @@ export const getFixedNumber = (
if (first.dataIndex === item.dataIndex) {
break;
}
count += item.width ?? 0;
count += item._resizeWidth ?? item.width ?? 0;
}
return count;
}
Expand Down

0 comments on commit 5153fce

Please sign in to comment.