Files
epg/scripts/core/table.js

48 lines
1.0 KiB
JavaScript
Raw Normal View History

2022-02-03 06:23:17 +03:00
const table = {}
table.create = function (data, cols) {
2022-10-22 04:35:16 +03:00
let output = '<table>\r\n'
2022-02-03 06:23:17 +03:00
2022-10-22 04:35:16 +03:00
output += ' <thead>\r\n <tr>'
2022-02-03 06:23:17 +03:00
for (let column of cols) {
2022-10-22 04:35:16 +03:00
output += `<th align="left">${column}</th>`
2022-02-03 06:23:17 +03:00
}
2022-10-22 04:35:16 +03:00
output += '</tr>\r\n </thead>\r\n'
2022-02-03 06:23:17 +03:00
2022-10-22 04:35:16 +03:00
output += ' <tbody>\r\n'
output += getHTMLRows(data)
output += ' </tbody>\r\n'
output += '</table>'
return output
}
function getHTMLRows(data) {
let output = ''
for (let group of data) {
let rowspan = group.length
for (let [j, row] of group.entries()) {
2022-02-03 06:23:17 +03:00
output += ' <tr>'
2022-10-22 04:35:16 +03:00
for (let [i, value] of row.entries()) {
if (i === 0 && j === 0) {
output += `<td valign="top" rowspan="${rowspan}">${value}</td>`
} else if (i > 0) {
if (typeof value === 'number') {
output += `<td align="right" nowrap>${value}</td>`
} else {
output += `<td nowrap>${value}</td>`
}
}
2022-02-03 06:23:17 +03:00
}
2022-10-22 04:35:16 +03:00
output += '</tr>\r\n'
2022-02-03 06:23:17 +03:00
}
}
return output
}
2022-10-22 04:35:16 +03:00
function getSpan() {}
2022-02-03 06:23:17 +03:00
module.exports = table