-
Notifications
You must be signed in to change notification settings - Fork 464
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
fix(table): resolve colspan handling for multi-header #4669
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 如果不是非必要,计算量大的表格里面,尽量减少 forEach 这类函数方法的使用 for 循环直接遍历,不需要创建函数,不需要创建函数的上下文 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 非常赞同,这里是少考虑了数据量的问题,数据量一旦过大的话在性能和内存占用上,forEach的却会有更大的开销,这里我一会到家调整下。 |
||
if (item.colspan > 1) { | ||
for (let j = 1; j < item.colspan; j++) { | ||
const nextIndex = i + j; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 如果逻辑一样的话, |
||
if (columns[nextIndex]) { | ||
map[columns[nextIndex].colKey] = true; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
// 如果有子列,递归处理 | ||
if (item.children) { | ||
processColumns(item.children); | ||
} | ||
}); | ||
}; | ||
|
||
const list = props.thList[0]; | ||
processColumns(list); | ||
|
||
return map; | ||
}); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的功能,还继续支持吗?
支持的话,代码恢复保留。
不支持的话,希望可以兼容处理,为曾经使用过的同学保留正确运行
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的功能依然是支持的,这里注释其实是为了不影响现有的文档,主要是感觉没必要再新增一个说明的文档,所以直接在多级表头的表格的demo下增加了一个
// colspan:
注释,或许可以增加个注释说明。当然,如果要移除的话,其实也不会有什么问题。