diff options
| -rw-r--r-- | grid/src/grid.ts | 34 |
1 files changed, 13 insertions, 21 deletions
diff --git a/grid/src/grid.ts b/grid/src/grid.ts index 3f59614..f263ac7 100644 --- a/grid/src/grid.ts +++ b/grid/src/grid.ts @@ -7,7 +7,7 @@ interface GridProps { columns: Array<GridColumn>; pageSize?: number; search?: SearchConfiguration; - tableClassName?: string; + tableClassName?: string } interface GridConfiguration { @@ -17,7 +17,7 @@ interface GridConfiguration { columns: Array<GridColumn>; pageSize: number; search: SearchConfiguration; - tableClassName: string; + tableClassName: string } interface SearchConfiguration { @@ -188,7 +188,7 @@ export default class Grid { } wrapper.innerHTML = ""; let items = data ?? this.configuration.data; - if (this.configuration.pageSize !== 0) { + if (this.configuration.pageSize > 0) { items = items.slice(0, this.configuration.pageSize); } for (const item of items) { @@ -197,31 +197,23 @@ export default class Grid { row.dataset.id = item[this.configuration.id]; for (const val of this.configuration.columns) { const cell = document.createElement("td"); + cell.className = "text-break"; if (val.width) cell.style.width = val.width; if (val.maxWidth) cell.style.maxWidth = val.maxWidth; if (val.minWidth) cell.style.minWidth = val.minWidth; - if (val.dataId !== undefined && val.dataId.length > 0) { - if (Array.isArray(val.dataId)) { - // @ts-ignore - val.cellValue = val.dataId; - this.log(val.dataId); - } else { - // @ts-ignore - val.cellValue = item[val.dataId]; - } - } - cell.className = "text-break"; - if (typeof val.cellValue === "string" || typeof val.cellValue === "number") { - cell.innerText = val.cellValue; - } else if (val.cellValue instanceof Element) { - cell.appendChild(val.cellValue); - } else if (val.cellValue instanceof Function) { + if (val.cellValue instanceof Function) { const computed = val.cellValue(item); if (computed instanceof Element) cell.appendChild(computed); else if (typeof computed === "string" || typeof computed === "number") cell.innerText = computed as string; - } else if (Array.isArray(val.cellValue)) { - cell.innerText = this.getNestedFieldValue(item, val.cellValue); + } else if (Array.isArray(val.dataId)) { + cell.innerText = this.getNestedFieldValue(item, val.dataId); + } else if (typeof val.dataId === "string" && val.dataId.length > 0) { + cell.innerText = item[val.dataId]; + } else if (typeof val.cellValue === "string" || typeof val.cellValue === "number") { + cell.innerText = val.cellValue; + } else if (val.cellValue instanceof Element) { + cell.appendChild(val.cellValue); } row.appendChild(cell); } |
