Skip to content

Commit 592c7b6

Browse files
authored
fix(table): add colLength judge (#479)
1 parent c3f3a09 commit 592c7b6

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

.changeset/perfect-years-tap.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@wangeditor-next/table-module': patch
3+
'@wangeditor-next/editor': patch
4+
---
5+
6+
fix(table): add colLength judge

packages/table-module/src/module/parse-elem-html.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,19 @@ function parseTableHtml(
127127
}
128128
const tdList = $elem.find('tr')[0]?.children || []
129129
const colgroupElments: HTMLCollection = $elem.find('colgroup')[0]?.children || null
130+
// @ts-ignore
131+
const colLength = children[children.length - 1].children.length
130132

131-
if (tdList.length > 0) {
133+
if (colgroupElments && colgroupElments.length === colLength) {
134+
tableELement.columnWidths = Array.from(colgroupElments).map((col: any) => {
135+
return parseInt(col.getAttribute('width'), 10)
136+
})
137+
} else if (tdList.length > 0) {
132138
const columnWidths: number[] = []
133139

134140
Array.from(tdList).forEach(td => {
135141
const colSpan = parseInt($(td).attr('colSpan') || '1', 10) // 获取 colSpan,默认为 1
136-
const width = parseInt(getStyleValue($(td), 'width') || '90', 10) // 获取 width,默认为 180
142+
const width = parseInt(getStyleValue($(td), 'width') || '90', 10) // 获取 width,默认为 90
137143

138144
// 根据 colSpan 的值来填充 columnWidths 数组
139145
columnWidths.push(width)
@@ -142,10 +148,6 @@ function parseTableHtml(
142148
}
143149
})
144150
tableELement.columnWidths = columnWidths
145-
} else if (colgroupElments) {
146-
tableELement.columnWidths = Array.from(colgroupElments).map((col: any) => {
147-
return parseInt(col.getAttribute('width'), 10)
148-
})
149151
}
150152
return tableELement
151153
}

0 commit comments

Comments
 (0)