Skip to content

Commit

Permalink
fix(table): resolve colspan handling for multi-header
Browse files Browse the repository at this point in the history
Added support for multi-header to ensure correct colspan calculation for child columns.

closed #4667
  • Loading branch information
wangyang0210 committed Oct 21, 2024
1 parent f475cc3 commit 56a9870
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/table/_example/multi-header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ function getColumns(fixedLeftCol, fixedRightCol) {
title: '审批单号',
fixed: fixedRightCol ? 'right' : undefined,
width: 120,
// colspan: 2,
},
{
colKey: 'detail.email',
Expand Down
28 changes: 19 additions & 9 deletions src/table/thead.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,27 @@ export default defineComponent({
// 单行表格合并
const colspanSkipMap = computed(() => {
const map: { [key: string]: boolean } = {};
const list = props.thList[0];
for (let i = 0, len = list.length; i < len; i++) {
const item = list[i];
if (item.colspan > 1) {
for (let j = i + 1; j < i + item.colspan; j++) {
if (list[j]) {
map[list[j].colKey] = true;

const processColumns = (columns: BaseTableColumns) => {
columns.forEach((item, i) => {
if (item.colspan > 1) {
for (let j = 1; j < item.colspan; j++) {
const nextIndex = i + j;
if (columns[nextIndex]) {
map[columns[nextIndex].colKey] = true;
}
}
}
}
}
// 如果有子列,递归处理
if (item.children) {
processColumns(item.children);
}
});
};

const list = props.thList[0];
processColumns(list);

return map;
});

Expand Down

0 comments on commit 56a9870

Please sign in to comment.