Skip to content

Commit 762ca7f

Browse files
committed
docs(data-table): add sortAlways examples
1 parent 44a85ea commit 762ca7f

1 file changed

Lines changed: 81 additions & 0 deletions

File tree

docs/src/pages/components/DataTable.svx

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,87 @@ Set `sortable` to `true` to enable column sorting. Disable sorting on specific c
946946
]}"
947947
/>
948948

949+
## Sortable (sort always)
950+
951+
Sortable columns support three directions: `none` (unsorted, original row order), `ascending`, and `descending`. Clicking a column header cycles through them in order.
952+
953+
By default, a third click on a sorted column unsorts it (`none` restores the original row order).
954+
955+
Set `sortAlways` to `true` to skip the unsorted state so the column always remains sorted. The first click goes to `ascending`; subsequent clicks alternate between `ascending` and `descending` (no `none`).
956+
957+
<DataTable sortable sortAlways
958+
headers="{[
959+
{ key: "name", value: "Name" },
960+
{ key: "protocol", value: "Protocol" },
961+
{ key: "port", value: "Port" },
962+
{ key: "rule", value: "Rule" }
963+
]}"
964+
rows="{[
965+
{
966+
id: "a",
967+
name: "Load Balancer 3",
968+
protocol: "HTTP",
969+
port: 3000,
970+
rule: "Round robin"
971+
},
972+
{
973+
id: "b",
974+
name: "Load Balancer 1",
975+
protocol: "HTTP",
976+
port: 443,
977+
rule: "Round robin"
978+
},
979+
{
980+
id: "c",
981+
name: "Load Balancer 2",
982+
protocol: "HTTP",
983+
port: 80,
984+
rule: "DNS delegation"
985+
},
986+
{
987+
id: "d",
988+
name: "Load Balancer 6",
989+
protocol: "HTTP",
990+
port: 3000,
991+
rule: "Round robin"
992+
},
993+
{
994+
id: "e",
995+
name: "Load Balancer 4",
996+
protocol: "HTTP",
997+
port: 443,
998+
rule: "Round robin"
999+
},
1000+
{
1001+
id: "f",
1002+
name: "Load Balancer 5",
1003+
protocol: "HTTP",
1004+
port: 80,
1005+
rule: "DNS delegation"
1006+
},
1007+
]}"
1008+
/>
1009+
1010+
## Sortable (per-column sortAlways)
1011+
1012+
Use `sortAlways` on individual headers to control which columns allow unsorting. In this transaction log, the Date column always stays sorted (chronological order is required for audit trails), while Amount and Status can be unsorted.
1013+
1014+
<DataTable sortable title="Recent transactions"
1015+
headers="{[
1016+
{ key: 'date', value: 'Date', sortAlways: true },
1017+
{ key: 'description', value: 'Description' },
1018+
{ key: 'amount', value: 'Amount' },
1019+
{ key: 'status', value: 'Status', sortAlways: false }
1020+
]}"
1021+
rows="{[
1022+
{ id: '1', date: '2025-03-05', description: 'Cloud hosting', amount: 149.00, status: 'Paid' },
1023+
{ id: '2', date: '2025-03-04', description: 'Domain renewal', amount: 12.99, status: 'Paid' },
1024+
{ id: '3', date: '2025-03-03', description: 'API subscription', amount: 49.00, status: 'Pending' },
1025+
{ id: '4', date: '2025-03-02', description: 'SSL certificate', amount: 0, status: 'Paid' },
1026+
{ id: '5', date: '2025-03-01', description: 'Backup storage', amount: 24.50, status: 'Failed' }
1027+
]}"
1028+
/>
1029+
9491030
## Sortable with pagination
9501031

9511032
Bind to `pageSize` and `page` props of the pagination component and pass them to the data table.

0 commit comments

Comments
 (0)