|
1 | | -import { html, css, LitElement, PropertyValues } from 'lit' |
| 1 | +import { html, css, LitElement, PropertyValues, nothing } from 'lit' |
2 | 2 | import { repeat } from 'lit/directives/repeat.js' |
3 | 3 | import { property, state, customElement } from 'lit/decorators.js' |
4 | 4 | import { InputData, Values } from './definition-schema.js' |
@@ -54,12 +54,17 @@ export class WidgetTable extends LitElement { |
54 | 54 | if (!this?.inputData?.columns?.length) return |
55 | 55 |
|
56 | 56 | const rows: any[][] = [] |
57 | | - this.inputData.columns.forEach((col, i) => { |
58 | | - col.values?.forEach((v, j) => { |
59 | | - if (rows.length <= j) rows.push([]) |
60 | | - rows[j].push(v) |
61 | | - }) |
62 | | - }) |
| 57 | + const cols = this.inputData.columns.map((col) => col?.values ?? []) |
| 58 | + const maxLength = Math.max(...cols.map((vals) => vals?.length ?? 0)) |
| 59 | + |
| 60 | + for (let r = 0; r < maxLength; r++) { |
| 61 | + rows.push([]) |
| 62 | + for (let c = 0; c < cols.length; c++) { |
| 63 | + const value = cols?.[c]?.[r] |
| 64 | + rows[r].push(value ?? {}) |
| 65 | + } |
| 66 | + } |
| 67 | + |
63 | 68 | this.rows = rows |
64 | 69 | } |
65 | 70 |
|
@@ -111,6 +116,7 @@ export class WidgetTable extends LitElement { |
111 | 116 | } |
112 | 117 |
|
113 | 118 | renderImage(cell: Values[number], colDef: Column) { |
| 119 | + if (!cell?.value) return nothing |
114 | 120 | return html`<a href="${cell?.link ?? ''}" target="_blank"><img src="${cell.value ?? ''}" /></a>` |
115 | 121 | } |
116 | 122 |
|
|
0 commit comments