Sortable table Web Component
The same table, with click-to-sort column headers.
How it helpsWrap any
<table> that has a <thead> and <tbody> in <sd-table>. Columns of numbers sort numerically, the rest as text. Add data-sort to a cell to sort by a different value than it shows.Click a header
| Date | Payee | Amount |
|---|---|---|
| 18 Nov | Blue Tokai | −₹420 |
| 17 Nov | Salary | ₹1,20,000 |
| 16 Nov | Zerodha SIP | −₹10,000 |
export default function Example() {
return (
<>
<sd-table className="w-full">
<div className="table-wrap">
<table>
<thead><tr><th>Date</th><th>Payee</th><th className="num">Amount</th></tr></thead>
<tbody>
<tr><td data-sort="2026-11-18">18 Nov</td><td>Blue Tokai</td><td className="num">−₹420</td></tr>
<tr><td data-sort="2026-11-17">17 Nov</td><td>Salary</td><td className="num">₹1,20,000</td></tr>
<tr><td data-sort="2026-11-16">16 Nov</td><td>Zerodha SIP</td><td className="num">−₹10,000</td></tr>
</tbody>
</table>
</div>
</sd-table>
</>
);
}<sd-table class="w-full">
<div class="table-wrap">
<table>
<thead><tr><th>Date</th><th>Payee</th><th class="num">Amount</th></tr></thead>
<tbody>
<tr><td data-sort="2026-11-18">18 Nov</td><td>Blue Tokai</td><td class="num">−₹420</td></tr>
<tr><td data-sort="2026-11-17">17 Nov</td><td>Salary</td><td class="num">₹1,20,000</td></tr>
<tr><td data-sort="2026-11-16">16 Nov</td><td>Zerodha SIP</td><td class="num">−₹10,000</td></tr>
</tbody>
</table>
</div>
</sd-table>In Next.js
// Client side: useSidedishEvent<{ column: number; direction: string }>(ref, "sort", (e) => e.detail.direction)API
| Name | Type | Description | |
|---|---|---|---|
sort | event | detail: { column, direction } | |
data-sort | attribute | On a | : the value to sort by. |