Skip to content

Commit aaa2f8a

Browse files
author
Marko Petzold
committed
fix: rename "Data Type" to "Column Type" in definition schema and optimize row data transformation in widget table
1 parent 6172dc4 commit aaa2f8a

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

src/definition-schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"order": 1
6161
},
6262
"type": {
63-
"title": "Data Type",
63+
"title": "Column Type",
6464
"enum": ["state", "string", "number", "boolean", "button", "image"],
6565
"type": "string",
6666
"dataDrivenDisabled": true,

src/widget-table.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { html, css, LitElement, PropertyValues } from 'lit'
1+
import { html, css, LitElement, PropertyValues, nothing } from 'lit'
22
import { repeat } from 'lit/directives/repeat.js'
33
import { property, state, customElement } from 'lit/decorators.js'
44
import { InputData, Values } from './definition-schema.js'
@@ -54,12 +54,17 @@ export class WidgetTable extends LitElement {
5454
if (!this?.inputData?.columns?.length) return
5555

5656
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+
6368
this.rows = rows
6469
}
6570

@@ -111,6 +116,7 @@ export class WidgetTable extends LitElement {
111116
}
112117

113118
renderImage(cell: Values[number], colDef: Column) {
119+
if (!cell?.value) return nothing
114120
return html`<a href="${cell?.link ?? ''}" target="_blank"><img src="${cell.value ?? ''}" /></a>`
115121
}
116122

0 commit comments

Comments
 (0)