Sorting
Sort table data by column to organize and prioritize information.
Example
Id
Name
Category
Price Retail
Status
1
Electronic Concrete Cheese
Clothing
35.04
low-stock
2
Small Steel Sausages
Beauty
419.74
in-stock
3
Licensed Silk Table
Beauty
347.56
in-stock
4
Tasty Marble Fish
Sports
432.39
in-stock
5
Soft Concrete Pants
Home & Garden
107.54
in-stock
6
Luxurious Ceramic Pizza
Home & Garden
229.65
in-stock
7
Bespoke Aluminum Salad
Home & Garden
207.15
in-stock
8
Handmade Wooden Hat
Sports
167.68
in-stock
9
Modern Plastic Pants
Clothing
456.36
in-stock
10
Modern Plastic Fish
Sports
45.59
in-stock
Per page:
Page 1 of 100
Showing
1
to
10
of 1000 rows
{#each datagrid.columns.getLeafColumnsInOrder() as column}
{@render LeafHeader(column)}
{/each}
{#each datagrid.rows.getPaginatedRows() as row}
{#if !row.isGroupRow()}
{#each datagrid.columns.getLeafColumnsInOrder() as column}
{@render RenderBodyCell(column, row)}
{/each}
{:else}{/if}
{/each}
{getCellContent(column, row.original)}
{/if}
{/snippet}
{#snippet LeafHeader(column: LeafColumn)}
{#if column.isVisible()}
datagrid.handlers.sorting.toggleColumnSort(column, e.ctrlKey)}
class={cn(
'th flex min-w-40 max-w-40 items-center justify-between gap-2 px-4 py-2',
column._meta.grow && '!max-w-full !grow',
column.isSortable() && 'cursor-pointer'
)}
style:--width={column.state.size.width + 'px'}
style:--min-width={column.state.size.minWidth + 'px'}
style:--max-width={column.state.size.maxWidth + 'px'}
>
{/if}
{/snippet}
{column.header}
{#if column.isSortable()}
{/if}