Skip to content

Commit e5943cf

Browse files
authored
Sorting + pagination example (#277)
* Sorting + pagination example * Fixed lint issue * Example improvements
1 parent 782dc82 commit e5943cf

File tree

1 file changed

+49
-0
lines changed
  • packages/svelte-ux/src/routes/docs/components/Table

1 file changed

+49
-0
lines changed

packages/svelte-ux/src/routes/docs/components/Table/+page.svelte

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,55 @@
160160
/>
161161
</Preview>
162162

163+
<h2>Order + Pagination</h2>
164+
165+
<Preview>
166+
<Paginate items={data.sort($order.handler)} perPage={5} let:pageItems let:pagination>
167+
<Table
168+
data={pageItems}
169+
columns={[
170+
{
171+
name: 'name',
172+
align: 'left',
173+
},
174+
{
175+
name: 'calories',
176+
align: 'right',
177+
format: 'integer',
178+
},
179+
{
180+
name: 'fat',
181+
align: 'right',
182+
format: 'integer',
183+
},
184+
{
185+
name: 'carbs',
186+
align: 'right',
187+
format: 'integer',
188+
},
189+
{
190+
name: 'protein',
191+
align: 'right',
192+
format: 'integer',
193+
},
194+
]}
195+
orderBy={$order.by}
196+
orderDirection={$order.direction}
197+
on:headerClick={(e) => {
198+
//Switch back to page 1 when sorting
199+
pagination.setPage(1);
200+
order.onHeaderClick(e.detail.column);
201+
}}
202+
/>
203+
<Pagination
204+
{pagination}
205+
perPageOptions={[5, 10, 25, 100]}
206+
show={['perPage', 'pagination', 'prevPage', 'nextPage']}
207+
classes={{ root: 'border-t py-1 mt-2', perPage: 'flex-1 text-right', pagination: 'px-8' }}
208+
/>
209+
</Paginate>
210+
</Preview>
211+
163212
<h2>Data background</h2>
164213

165214
<Preview>

0 commit comments

Comments
 (0)