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) {
$table.addClass(`table-${options.variant}`)
}
if (options.fixed_layout) {
$table.css('table-layout', 'fixed')
}
if (options.tableClass) {
$table.addClass(options.tableClass)
}
const $caption = $('<caption/>')
let $caption = null
if (options.caption) {
$caption = $('<caption/>')
if (options.caption instanceof jQuery) {
$caption = options.caption
} else {
@ -1137,7 +1141,9 @@ class HtmlHelper {
}
}
const $theadRow = $('<tr/>')
let $theadRow = null
if (head) {
$theadRow = $('<tr/>')
head.forEach(head => {
if (head instanceof jQuery) {
$theadRow.append($('<td/>').append(head))
@ -1146,12 +1152,17 @@ class HtmlHelper {
}
})
$thead.append($theadRow)
}
body.forEach(row => {
const $bodyRow = $('<tr/>')
row.forEach(item => {
if (item instanceof jQuery) {
if (item.is('td')) {
$bodyRow.append(item)
} else {
$bodyRow.append($('<td/>').append(item))
}
} else {
$bodyRow.append($('<td/>').text(item))
}