Skip to content

Commit

Permalink
doc: update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryan Lee committed May 26, 2022
1 parent c20abdb commit 3816b45
Showing 1 changed file with 47 additions and 46 deletions.
93 changes: 47 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,57 +64,58 @@ Svelte Headless Table comes with a stable plugin system that allows you to trans

## Examples

<!-- prettier-ignore -->
```svelte
<script>
const data = readable([
{ name: 'Ada Lovelace', age: 21 },
{ name: 'Barbara Liskov', age: 52 },
{ name: 'Richard Hamming', age: 38 },
]);
const table = createTable(data);
const columns = table.createColumns([
table.column({
header: 'Name',
accessor: 'name',
}),
table.column({
header: 'Age',
accessor: 'age',
}),
]);
const { headerRows, rows } = table.createViewModel(columns);
const data = readable([
{ name: 'Ada Lovelace', age: 21 },
{ name: 'Barbara Liskov', age: 52 },
{ name: 'Richard Hamming', age: 38 },
]);
const table = createTable(data);
const columns = table.createColumns([
table.column({
header: 'Name',
accessor: 'name',
}),
table.column({
header: 'Age',
accessor: 'age',
}),
]);
const { headerRows, rows } = table.createViewModel(columns);
</script>
<table>
<thead>
{#each $headerRows as headerRow (headerRow.id)}
<tr>
{#each headerRow.cells as cell (cell.id)}
<Subscribe attrs={cell.attrs()} let:attrs>
<th {...attrs}>
<Render of={cell.render()} />
</th>
</Subscribe>
{/each}
</tr>
{/each}
</thead>
<tbody>
{#each $rows as row (row.id)}
<tr>
{#each row.cells as cell (cell.id)}
<Subscribe attrs={cell.attrs()} let:attrs>
<td {...attrs}>
<Render of={cell.render()} />
</td>
</Subscribe>
{/each}
</tr>
{/each}
</tbody>
<thead>
{#each $headerRows as headerRow (headerRow.id)}
<tr>
{#each headerRow.cells as cell (cell.id)}
<Subscribe attrs={cell.attrs()} let:attrs>
<th {...attrs}>
<Render of={cell.render()} />
</th>
</Subscribe>
{/each}
</tr>
{/each}
</thead>
<tbody>
{#each $rows as row (row.id)}
<tr>
{#each row.cells as cell (cell.id)}
<Subscribe attrs={cell.attrs()} let:attrs>
<td {...attrs}>
<Render of={cell.render()} />
</td>
</Subscribe>
{/each}
</tr>
{/each}
</tbody>
</table>
```

Expand Down

0 comments on commit 3816b45

Please sign in to comment.