chg: [js:bootstrap-helper] Improved table building mechanism

develop-unstable
Sami Mokaddem 2022-12-02 09:46:40 +01:00
parent 48a3c242aa
commit f1c84ff834
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
1 changed files with 22 additions and 11 deletions

View File

@ -1124,12 +1124,16 @@ class HtmlHelper {
if (options.variant) { if (options.variant) {
$table.addClass(`table-${options.variant}`) $table.addClass(`table-${options.variant}`)
} }
if (options.fixed_layout) {
$table.css('table-layout', 'fixed')
}
if (options.tableClass) { if (options.tableClass) {
$table.addClass(options.tableClass) $table.addClass(options.tableClass)
} }
const $caption = $('<caption/>') let $caption = null
if (options.caption) { if (options.caption) {
$caption = $('<caption/>')
if (options.caption instanceof jQuery) { if (options.caption instanceof jQuery) {
$caption = options.caption $caption = options.caption
} else { } else {
@ -1137,21 +1141,28 @@ class HtmlHelper {
} }
} }
const $theadRow = $('<tr/>') let $theadRow = null
head.forEach(head => { if (head) {
if (head instanceof jQuery) { $theadRow = $('<tr/>')
$theadRow.append($('<td/>').append(head)) head.forEach(head => {
} else { if (head instanceof jQuery) {
$theadRow.append($('<th/>').text(head)) $theadRow.append($('<td/>').append(head))
} } else {
}) $theadRow.append($('<th/>').text(head))
$thead.append($theadRow) }
})
$thead.append($theadRow)
}
body.forEach(row => { body.forEach(row => {
const $bodyRow = $('<tr/>') const $bodyRow = $('<tr/>')
row.forEach(item => { row.forEach(item => {
if (item instanceof jQuery) { if (item instanceof jQuery) {
$bodyRow.append($('<td/>').append(item)) if (item.is('td')) {
$bodyRow.append(item)
} else {
$bodyRow.append($('<td/>').append(item))
}
} else { } else {
$bodyRow.append($('<td/>').text(item)) $bodyRow.append($('<td/>').text(item))
} }