Skip to content

Commit 5e3c721

Browse files
committed
doc: add grid layout example
1 parent 28eaf56 commit 5e3c721

File tree

4 files changed

+110
-8
lines changed

4 files changed

+110
-8
lines changed

docs/package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"shiki": "^0.10.1",
3838
"svelte": "^3.44.0",
3939
"svelte-check": "^2.2.6",
40-
"svelte-headless-table": "^0.15.0",
40+
"svelte-headless-table": "^0.15.1",
4141
"svelte-preprocess": "^4.10.5",
4242
"tailwindcss": "^3.0.24",
4343
"tslib": "^2.3.1",

docs/src/routes/docs/[...3]plugins/[...13]add-grid-layout.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,18 @@ sidebar_title: addGridLayout
1212
# {$frontmatter.title}
1313

1414
`addGridLayout` configures the table to use [CSS Grid Layout](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout) for laying out the table.
15+
16+
## Examples
17+
18+
### CSS Grid layout
19+
20+
:::example
21+
22+
[REPL](https://svelte.dev/repl/1cbeae0c59f0468d9d18b0b7d65e4b0e?version=3.50.1)
23+
24+
<script>
25+
import SimpleGridLayoutDemo from './_demo/SimpleGridLayoutDemo.svelte'
26+
</script>
27+
<SimpleGridLayoutDemo />
28+
29+
:::
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<script>
2+
import { derived, readable } from 'svelte/store';
3+
import { createTable, Subscribe, Render } from 'svelte-headless-table';
4+
import { addGridLayout } from 'svelte-headless-table/plugins';
5+
import { createSamples } from '$lib/utils/createSamples';
6+
7+
const data = readable(createSamples(10, 5, 3));
8+
9+
const table = createTable(data, {
10+
grid: addGridLayout(),
11+
});
12+
13+
const columns = table.createColumns([
14+
table.group({
15+
header: (_, { rows }) => derived([rows], ([_rows]) => `Name (${_rows.length} users)`),
16+
columns: [
17+
table.column({
18+
header: 'First Name',
19+
accessor: 'firstName',
20+
}),
21+
table.column({
22+
header: 'Last Name',
23+
accessor: 'lastName',
24+
}),
25+
],
26+
}),
27+
table.group({
28+
header: 'Info',
29+
columns: [
30+
table.column({
31+
header: 'Age',
32+
accessor: 'age',
33+
}),
34+
table.column({
35+
header: 'Status',
36+
accessor: 'status',
37+
}),
38+
table.column({
39+
header: 'Visits',
40+
accessor: 'visits',
41+
}),
42+
table.column({
43+
header: 'Profile Progress',
44+
accessor: 'progress',
45+
}),
46+
],
47+
}),
48+
]);
49+
50+
const { headerRows, rows, tableAttrs, tableHeadAttrs, tableBodyAttrs } =
51+
table.createViewModel(columns);
52+
</script>
53+
54+
<div class="overflow-x-auto">
55+
<table class="demo my-0" {...$tableAttrs}>
56+
<thead {...$tableHeadAttrs}>
57+
{#each $headerRows as headerRow (headerRow.id)}
58+
<Subscribe rowAttrs={headerRow.attrs()} let:rowAttrs>
59+
<tr {...rowAttrs}>
60+
{#each headerRow.cells as cell (cell.id)}
61+
<Subscribe attrs={cell.attrs()} let:attrs>
62+
<th {...attrs}>
63+
<Render of={cell.render()} />
64+
</th>
65+
</Subscribe>
66+
{/each}
67+
</tr>
68+
</Subscribe>
69+
{/each}
70+
</thead>
71+
<tbody {...$tableBodyAttrs}>
72+
{#each $rows as row (row.id)}
73+
<Subscribe rowAttrs={row.attrs()} let:rowAttrs>
74+
<tr {...rowAttrs}>
75+
{#each row.cells as cell (cell.id)}
76+
<Subscribe attrs={cell.attrs()} let:attrs>
77+
<td {...attrs}>
78+
<Render of={cell.render()} />
79+
</td>
80+
</Subscribe>
81+
{/each}
82+
</tr>
83+
</Subscribe>
84+
{/each}
85+
</tbody>
86+
</table>
87+
</div>

0 commit comments

Comments
 (0)