Lib: Add on-click handler prop to table component
This commit is contained in:
@ -7,9 +7,12 @@
|
|||||||
|
|
||||||
/** The columns the table should have. */
|
/** The columns the table should have. */
|
||||||
columns: TableColumn[];
|
columns: TableColumn[];
|
||||||
|
|
||||||
|
/** An optional function handling clicking on a table row */
|
||||||
|
handler?: (event: Event, id: string) => Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
let { data, columns }: TableProps = $props();
|
let { data, columns, handler = undefined }: TableProps = $props();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="table-container bg-white shadow">
|
<div class="table-container bg-white shadow">
|
||||||
@ -21,24 +24,23 @@
|
|||||||
{/each}
|
{/each}
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
||||||
<tbody>
|
<tbody>
|
||||||
{#each data as row}
|
{#each data as row}
|
||||||
<tr>
|
<tr
|
||||||
|
onclick={async (event: Event) => {
|
||||||
|
if (handler) await handler(event, row.id);
|
||||||
|
}}
|
||||||
|
>
|
||||||
{#each columns as col}
|
{#each columns as col}
|
||||||
{#if col.valuefun}
|
{#if col.valuefun}
|
||||||
<td>{@html col.valuefun(row[col.data_value_name])}</td>
|
<td class="!align-middle">{@html col.valuefun(row[col.data_value_name])}</td>
|
||||||
{:else}
|
{:else}
|
||||||
<td>{row[col.data_value_name]}</td>
|
<td class="!align-middle">{row[col.data_value_name]}</td>
|
||||||
{/if}
|
{/if}
|
||||||
{/each}
|
{/each}
|
||||||
</tr>
|
</tr>
|
||||||
{/each}
|
{/each}
|
||||||
</tbody>
|
</tbody>
|
||||||
<!-- <tfoot> -->
|
|
||||||
<!-- <tr> -->
|
|
||||||
<!-- <th colspan="3">Calculated Total Weight</th> -->
|
|
||||||
<!-- <td>{totalWeight}</td> -->
|
|
||||||
<!-- </tr> -->
|
|
||||||
<!-- </tfoot> -->
|
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user