Reputation: 49
how can I add the event to the table, so that it can save the data of the selected row in a variable, when I click on the row?
Upvotes: 0
Views: 1902
Reputation: 5426
Looking at the docs, svelte-simple-datatables
lets you pass in a template for the rows. This means you can add a click event listener to the tr
. Modified example of the readme:
<script>
import { Datatable, rows } from 'svelte-simple-datatables'
const settings = {
sortable: true,
pagination: true,
rowPerPage: 50,
columnFilter: true,
}
let data = [ {} /* ..your data*/];
let selectedIndex = -1;
</script>
<Datatable settings={settings} data={data}>
<thead>
<!-- header definition .. -->
</thead>
<tbody>
{#each $rows as row, index}
<tr on:click={() => selectedIndex = index}>
<td>{row.id}</td>
<!-- etc.. -->
</tr>
{/each}
</tbody>
</Datatable>
Upvotes: 1