Files
iptv/scripts/core/htmlTable.ts

47 lines
995 B
TypeScript
Raw Normal View History

2023-09-15 18:40:35 +03:00
type Column = {
name: string
nowrap?: boolean
align?: string
}
type DataItem = string[]
export class HTMLTable {
data: DataItem[]
columns: Column[]
constructor(data: DataItem[], columns: Column[]) {
this.data = data
this.columns = columns
}
toString() {
2025-04-22 23:30:34 +03:00
let output = '<table>\r\n'
2023-09-15 18:40:35 +03:00
2025-04-22 23:30:34 +03:00
output += ' <thead>\r\n <tr>'
2023-09-22 06:22:47 +03:00
for (const column of this.columns) {
2023-09-15 18:40:35 +03:00
output += `<th align="left">${column.name}</th>`
}
2025-04-22 23:30:34 +03:00
output += '</tr>\r\n </thead>\r\n'
2023-09-15 18:40:35 +03:00
2025-04-22 23:30:34 +03:00
output += ' <tbody>\r\n'
2023-09-22 06:22:47 +03:00
for (const item of this.data) {
2023-09-15 18:40:35 +03:00
output += ' <tr>'
let i = 0
2023-09-22 06:22:47 +03:00
for (const prop in item) {
2023-09-15 18:40:35 +03:00
const column = this.columns[i]
2023-09-22 06:22:47 +03:00
const nowrap = column.nowrap ? ' nowrap' : ''
const align = column.align ? ` align="${column.align}"` : ''
2023-09-15 18:40:35 +03:00
output += `<td${align}${nowrap}>${item[prop]}</td>`
i++
}
2025-04-22 23:30:34 +03:00
output += '</tr>\r\n'
2023-09-15 18:40:35 +03:00
}
2025-04-22 23:30:34 +03:00
output += ' </tbody>\r\n'
2023-09-15 18:40:35 +03:00
output += '</table>'
return output
}
}