diff --git a/src/lib/components/Table.svelte b/src/lib/components/Table.svelte index 87516e5..0b31530 100644 --- a/src/lib/components/Table.svelte +++ b/src/lib/components/Table.svelte @@ -7,9 +7,12 @@ /** The columns the table should have. */ columns: TableColumn[]; + + /** An optional function handling clicking on a table row */ + handler?: (event: Event, id: string) => Promise; } - let { data, columns }: TableProps = $props(); + let { data, columns, handler = undefined }: TableProps = $props();
@@ -21,24 +24,23 @@ {/each} + {#each data as row} - + { + if (handler) await handler(event, row.id); + }} + > {#each columns as col} {#if col.valuefun} - {@html col.valuefun(row[col.data_value_name])} + {@html col.valuefun(row[col.data_value_name])} {:else} - {row[col.data_value_name]} + {row[col.data_value_name]} {/if} {/each} {/each} - - - - - -