Enable row selection
To enable row selection, rows must have at least a unique id field.
This unique id must be defined in TableHandler
params:
const table = new TableHandler(data, { selectBy: 'id' })
Select a row
- Is row selected ?
table.selected.includes(id)
- Select a row:
table.select(id)
{#each table.rows as row}
<tr class:active={table.selected.includes(row.id)}>
<td>
<input type="checkbox"
checked={table.selected.includes(row.id)}
onclick={() => table.select(row.id)}
>
</td>
</tr>
{/each}
Avatar | Fristname | Lastname | Age | |
---|---|---|---|---|
Emily | Johnson | 28 | ||
Michael | Williams | 35 | ||
Sophia | Brown | 42 | ||
James | Davis | 45 | ||
Emma | Miller | 30 | ||
Olivia | Wilson | 22 | ||
Alexander | Jones | 38 | ||
Ava | Taylor | 27 | ||
Ethan | Martinez | 33 | ||
Isabella | Anderson | 31 |