Sortable Table
Sort server-rendered rows from the column headers and open a row from anywhere in it.
| Product | Category | Status | Actions |
|---|---|---|---|
| Arc Task Lamp | Lighting | Active | |
| Ash Lounge Chair | Furniture | Archived | |
| Brass Candle Holder | Objects | Active | |
| Halo Pendant | Lighting | Draft | |
| Linen Cushion | Textiles | Draft | |
| Oak Side Table | Furniture | Active | |
| Stone Vase | Objects | Active | |
| Woven Throw | Textiles | Archived |
HTML
<div class="mero-scope" data-mero-scope>
<section class="mero-records" data-mero-records data-mero-restore-focus hx-target="this" hx-select="[data-mero-records]" hx-swap="outerHTML show:none" hx-sync="this:replace">
<div class="mero-table-wrap">
<table class="mero-table mero-table-compact">
<caption id="records-count">Studio products · 8 of 8</caption>
<thead hx-boost="true"><tr>
<th scope="col" aria-sort="ascending"><a id="records-sort-name" href="?sort=-name">Product <span aria-hidden="true">↑</span></a></th>
<th scope="col"><a id="records-sort-category" href="?sort=category">Category</a></th>
<th scope="col"><a id="records-sort-status" href="?sort=status">Status</a></th>
<th scope="col">Actions</th>
</tr></thead>
<tbody>
<tr>
<th scope="row"><a class="mero-row-link" href="?sort=name&open=1">Arc Task Lamp</a></th>
<td>Lighting</td>
<td><span class="mero-badge mero-badge-success">Active</span></td>
<td>
<button class="mero-button mero-button-ghost mero-button-sm" id="records-1-actions" type="button" popovertarget="records-1-menu" aria-haspopup="menu" aria-expanded="false" aria-label="Actions for Arc Task Lamp">Actions</button>
<div class="mero-popover mero-menu" id="records-1-menu" popover role="menu" aria-label="Arc Task Lamp actions">
<a class="mero-menu-item" role="menuitem" href="?sort=name&open=1">Open details</a>
<a class="mero-menu-item" role="menuitem" href="/components/data-grid">Edit in inventory</a>
</div>
</td>
</tr>
<tr>
<th scope="row"><a class="mero-row-link" href="?sort=name&open=7">Ash Lounge Chair</a></th>
<td>Furniture</td>
<td><span class="mero-badge">Archived</span></td>
<td>
<button class="mero-button mero-button-ghost mero-button-sm" id="records-7-actions" type="button" popovertarget="records-7-menu" aria-haspopup="menu" aria-expanded="false" aria-label="Actions for Ash Lounge Chair">Actions</button>
<div class="mero-popover mero-menu" id="records-7-menu" popover role="menu" aria-label="Ash Lounge Chair actions">
<a class="mero-menu-item" role="menuitem" href="?sort=name&open=7">Open details</a>
<a class="mero-menu-item" role="menuitem" href="/components/data-grid">Edit in inventory</a>
</div>
</td>
</tr>
<tr>
<th scope="row"><a class="mero-row-link" href="?sort=name&open=8">Brass Candle Holder</a></th>
<td>Objects</td>
<td><span class="mero-badge mero-badge-success">Active</span></td>
<td>
<button class="mero-button mero-button-ghost mero-button-sm" id="records-8-actions" type="button" popovertarget="records-8-menu" aria-haspopup="menu" aria-expanded="false" aria-label="Actions for Brass Candle Holder">Actions</button>
<div class="mero-popover mero-menu" id="records-8-menu" popover role="menu" aria-label="Brass Candle Holder actions">
<a class="mero-menu-item" role="menuitem" href="?sort=name&open=8">Open details</a>
<a class="mero-menu-item" role="menuitem" href="/components/data-grid">Edit in inventory</a>
</div>
</td>
</tr>
<tr>
<th scope="row"><a class="mero-row-link" href="?sort=name&open=2">Halo Pendant</a></th>
<td>Lighting</td>
<td><span class="mero-badge mero-badge-warning">Draft</span></td>
<td>
<button class="mero-button mero-button-ghost mero-button-sm" id="records-2-actions" type="button" popovertarget="records-2-menu" aria-haspopup="menu" aria-expanded="false" aria-label="Actions for Halo Pendant">Actions</button>
<div class="mero-popover mero-menu" id="records-2-menu" popover role="menu" aria-label="Halo Pendant actions">
<a class="mero-menu-item" role="menuitem" href="?sort=name&open=2">Open details</a>
<a class="mero-menu-item" role="menuitem" href="/components/data-grid">Edit in inventory</a>
</div>
</td>
</tr>
<tr>
<th scope="row"><a class="mero-row-link" href="?sort=name&open=6">Linen Cushion</a></th>
<td>Textiles</td>
<td><span class="mero-badge mero-badge-warning">Draft</span></td>
<td>
<button class="mero-button mero-button-ghost mero-button-sm" id="records-6-actions" type="button" popovertarget="records-6-menu" aria-haspopup="menu" aria-expanded="false" aria-label="Actions for Linen Cushion">Actions</button>
<div class="mero-popover mero-menu" id="records-6-menu" popover role="menu" aria-label="Linen Cushion actions">
<a class="mero-menu-item" role="menuitem" href="?sort=name&open=6">Open details</a>
<a class="mero-menu-item" role="menuitem" href="/components/data-grid">Edit in inventory</a>
</div>
</td>
</tr>
<tr>
<th scope="row"><a class="mero-row-link" href="?sort=name&open=3">Oak Side Table</a></th>
<td>Furniture</td>
<td><span class="mero-badge mero-badge-success">Active</span></td>
<td>
<button class="mero-button mero-button-ghost mero-button-sm" id="records-3-actions" type="button" popovertarget="records-3-menu" aria-haspopup="menu" aria-expanded="false" aria-label="Actions for Oak Side Table">Actions</button>
<div class="mero-popover mero-menu" id="records-3-menu" popover role="menu" aria-label="Oak Side Table actions">
<a class="mero-menu-item" role="menuitem" href="?sort=name&open=3">Open details</a>
<a class="mero-menu-item" role="menuitem" href="/components/data-grid">Edit in inventory</a>
</div>
</td>
</tr>
<tr>
<th scope="row"><a class="mero-row-link" href="?sort=name&open=5">Stone Vase</a></th>
<td>Objects</td>
<td><span class="mero-badge mero-badge-success">Active</span></td>
<td>
<button class="mero-button mero-button-ghost mero-button-sm" id="records-5-actions" type="button" popovertarget="records-5-menu" aria-haspopup="menu" aria-expanded="false" aria-label="Actions for Stone Vase">Actions</button>
<div class="mero-popover mero-menu" id="records-5-menu" popover role="menu" aria-label="Stone Vase actions">
<a class="mero-menu-item" role="menuitem" href="?sort=name&open=5">Open details</a>
<a class="mero-menu-item" role="menuitem" href="/components/data-grid">Edit in inventory</a>
</div>
</td>
</tr>
<tr>
<th scope="row"><a class="mero-row-link" href="?sort=name&open=4">Woven Throw</a></th>
<td>Textiles</td>
<td><span class="mero-badge">Archived</span></td>
<td>
<button class="mero-button mero-button-ghost mero-button-sm" id="records-4-actions" type="button" popovertarget="records-4-menu" aria-haspopup="menu" aria-expanded="false" aria-label="Actions for Woven Throw">Actions</button>
<div class="mero-popover mero-menu" id="records-4-menu" popover role="menu" aria-label="Woven Throw actions">
<a class="mero-menu-item" role="menuitem" href="?sort=name&open=4">Open details</a>
<a class="mero-menu-item" role="menuitem" href="/components/data-grid">Edit in inventory</a>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
</div>HTTP exchange
Use the preview to see the request and the HTML your server returns.Each header links to ?sort=column, and a leading minus sorts descending. The server marks the sorted column with aria-sort. Each row has one real link whose pseudo-element covers the row, so the row's menu keeps working. Remove mero-table-compact for regular density. With HTMX, hx-boost swaps only the table and pushes the URL. data-mero-restore-focus returns focus to the opened row after Back.
Use in your app
Copy these tags into your page head once. Serve the files at the paths shown, then add the example’s template to your page.
Page assets
<link rel="stylesheet" href="/mero.css">
<script defer src="/vendor/htmx.min.js"></script>
<script defer src="/mero.js"></script>Point the HTMX attributes at your own HTML endpoints. Use the live preview’s HTTP exchange to inspect the request and response.
Download library and examples ↓