Lib: Hide table header if no data is passed

This commit is contained in:
2025-01-27 19:43:45 +01:00
parent a34cf50ace
commit 986a49377b

View File

@ -15,35 +15,37 @@
let { data, columns, handler = undefined }: TableProps = $props();
</script>
<div class="table-container bg-white shadow">
<table class="table table-compact bg-white">
<thead>
<tr class="bg-surface-500">
{#each columns as col}
<th class="!px-3">{col.label}</th>
{/each}
</tr>
</thead>
<tbody>
{#each data as row}
<tr
class="cursor-pointer bg-surface-300"
onclick={async (event: Event) => {
if (handler) await handler(event, row.id);
}}
>
{#if data.length > 0}
<div class="table-container bg-white shadow">
<table class="table table-compact bg-white">
<thead>
<tr class="bg-surface-500">
{#each columns as col}
{#if col.valuefun}
<td class="!align-middle">
{#await col.valuefun(row[col.data_value_name]) then value}{@html value}{/await}
</td>
{:else}
<td class="!align-middle">{row[col.data_value_name]}</td>
{/if}
<th class="!px-3">{col.label}</th>
{/each}
</tr>
{/each}
</tbody>
</table>
</div>
</thead>
<tbody>
{#each data as row}
<tr
class="cursor-pointer bg-surface-300"
onclick={async (event: Event) => {
if (handler) await handler(event, row.id);
}}
>
{#each columns as col}
{#if col.valuefun}
<td class="!align-middle">
{#await col.valuefun(row[col.data_value_name]) then value}{@html value}{/await}
</td>
{:else}
<td class="!align-middle">{row[col.data_value_name]}</td>
{/if}
{/each}
</tr>
{/each}
</tbody>
</table>
</div>
{/if}