Data table
The plain table, with superpowers: search, pages, sorting, rows that open, tree rows, groups that fold, and cells you can edit in place. Each is one attribute or class, and they all work together.
Search, pages and sorting
Add data-momo-datatable to the table. It gets a search box above, and under it the count, a "rows per page" picker and page buttons. Headers sort. data-page-size sets the rows per page (10), data-page-sizes the choices ("" hides the picker), data-search="false" hides the search, and data-noun names the rows in the count.
| Name | Role | City | Joined |
|---|---|---|---|
| Ana Kim | Designer | Toronto | 2019 |
| Max Ruiz | Support | Madrid | 2021 |
| Lea Novak | Engineer | Ljubljana | 2018 |
| Sam Okafor | Sales | Lagos | 2022 |
| Iris Tan | Engineer | Singapore | 2020 |
| Omar Haddad | Designer | Amman | 2023 |
| Nora Berg | Product | Oslo | 2017 |
| Luis Mora | Engineer | Lima | 2021 |
| Yuki Sato | Support | Osaka | 2020 |
| Chloé Martin | Marketing | Lyon | 2022 |
| Dara Singh | Sales | Delhi | 2019 |
| Ben Cole | Engineer | Dublin | 2024 |
| Mia Rossi | Product | Milan | 2018 |
<div class="table-wrap">
<table class="table table-hover" data-momo-datatable data-page-size="5" data-page-sizes="5,10,20" data-noun="people" aria-label="Team">
<thead><tr><th>Name</th><th>Role</th><th>City</th><th class="num">Joined</th></tr></thead>
<tbody>
<tr><td>Ana Kim</td><td>Designer</td><td>Toronto</td><td class="num">2019</td></tr>
<tr><td>Max Ruiz</td><td>Support</td><td>Madrid</td><td class="num">2021</td></tr>
<tr><td>Lea Novak</td><td>Engineer</td><td>Ljubljana</td><td class="num">2018</td></tr>
<tr><td>Sam Okafor</td><td>Sales</td><td>Lagos</td><td class="num">2022</td></tr>
<tr><td>Iris Tan</td><td>Engineer</td><td>Singapore</td><td class="num">2020</td></tr>
<tr><td>Omar Haddad</td><td>Designer</td><td>Amman</td><td class="num">2023</td></tr>
<tr><td>Nora Berg</td><td>Product</td><td>Oslo</td><td class="num">2017</td></tr>
<tr><td>Luis Mora</td><td>Engineer</td><td>Lima</td><td class="num">2021</td></tr>
<tr><td>Yuki Sato</td><td>Support</td><td>Osaka</td><td class="num">2020</td></tr>
<tr><td>Chloé Martin</td><td>Marketing</td><td>Lyon</td><td class="num">2022</td></tr>
<tr><td>Dara Singh</td><td>Sales</td><td>Delhi</td><td class="num">2019</td></tr>
<tr><td>Ben Cole</td><td>Engineer</td><td>Dublin</td><td class="num">2024</td></tr>
<tr><td>Mia Rossi</td><td>Product</td><td>Milan</td><td class="num">2018</td></tr>
</tbody>
</table>
</div>table.addEventListener('momo:page', (e) => console.log(e.detail.page, e.detail.pages, e.detail.total));
Momo.table.page(table, 2);
Momo.table.search(table, 'engineer');Rows that open
Put a <button class="row-toggle" data-momo-row-toggle> in a row and a tr.row-detail (hidden) right under it: the button opens it. Anything fits inside, even another table. Sorting and pages keep the detail with its row.
| Order | Customer | Total | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| #10421 | Ana Kim | $129.00 | ||||||||||||
| ||||||||||||||
| #10422 | Max Ruiz | $58.00 | ||||||||||||
Ships to Calle Mayor 12, Madrid. Note: leave at the door. | ||||||||||||||
| #10423 | Lea Novak | $212.00 | ||||||||||||
Gift wrapped, with a card. | ||||||||||||||
<div class="table-wrap">
<table class="table" data-momo-sort>
<thead><tr><th>Order</th><th>Customer</th><th class="num">Total</th></tr></thead>
<tbody>
<tr><td><button class="row-toggle" type="button" data-momo-row-toggle aria-label="Show items of #10421"></button>#10421</td><td>Ana Kim</td><td class="num">$129.00</td></tr>
<tr class="row-detail" hidden><td colspan="3"><div class="row-detail-body">
<table class="table table-sm table-flush m-0"><thead><tr><th>Item</th><th class="num">Qty</th><th class="num">Price</th></tr></thead><tbody><tr><td>Momo Mug</td><td class="num">2</td><td class="num">$48.00</td></tr><tr><td>Canvas tote</td><td class="num">1</td><td class="num">$29.00</td></tr><tr><td>Sticker pack</td><td class="num">4</td><td class="num">$52.00</td></tr></tbody></table>
</div></td></tr>
<tr><td><button class="row-toggle" type="button" data-momo-row-toggle aria-label="Show items of #10422"></button>#10422</td><td>Max Ruiz</td><td class="num">$58.00</td></tr>
<tr class="row-detail" hidden><td colspan="3"><div class="row-detail-body"><p class="m-0"><b>Ships to</b> Calle Mayor 12, Madrid. <b>Note:</b> leave at the door.</p></div></td></tr>
<tr><td><button class="row-toggle" type="button" data-momo-row-toggle aria-label="Show items of #10423"></button>#10423</td><td>Lea Novak</td><td class="num">$212.00</td></tr>
<tr class="row-detail" hidden><td colspan="3"><div class="row-detail-body"><p class="m-0">Gift wrapped, with a card.</p></div></td></tr>
</tbody>
</table>
</div>Tree rows
Give rows data-level="1", "2", "3": the first cell indents, and a row with deeper rows under it gets a fold button. Folding hides everything under it; a folded row inside stays folded when you open its parent again.
| Folder | Owner | Size |
|---|---|---|
| Design | Ana | 2.4 GB |
| Brand | Ana | 820 MB |
| logo.svg | Ana | 24 KB |
| colors.pdf | Ana | 1.2 MB |
| Website | Iris | 1.6 GB |
| Finance | Nora | 340 MB |
| 2026 budget.xlsx | Nora | 2 MB |
| Readme.txt | Max | 4 KB |
<div class="table-wrap">
<table class="table" id="tbl-tree">
<thead><tr><th>Folder</th><th>Owner</th><th class="num">Size</th></tr></thead>
<tbody>
<tr data-level="1"><td>Design</td><td>Ana</td><td class="num">2.4 GB</td></tr>
<tr data-level="2"><td>Brand</td><td>Ana</td><td class="num">820 MB</td></tr>
<tr data-level="3"><td>logo.svg</td><td>Ana</td><td class="num">24 KB</td></tr>
<tr data-level="3"><td>colors.pdf</td><td>Ana</td><td class="num">1.2 MB</td></tr>
<tr data-level="2"><td>Website</td><td>Iris</td><td class="num">1.6 GB</td></tr>
<tr data-level="1"><td>Finance</td><td>Nora</td><td class="num">340 MB</td></tr>
<tr data-level="2"><td>2026 budget.xlsx</td><td>Nora</td><td class="num">2 MB</td></tr>
<tr data-level="1"><td>Readme.txt</td><td>Max</td><td class="num">4 KB</td></tr>
</tbody>
</table>
</div>Groups
A tr.row-group with one cell starts a group: click it to fold the rows under it. A <span class="badge-count" data-momo-count> inside counts the rows by itself. Sorting sorts inside each group.
| Product | Stock | Price |
|---|---|---|
| Kitchen | ||
| Momo Mug | 4 | $24.00 |
| Plate set | 31 | $58.00 |
| Tea towel | 120 | $12.00 |
| Bags | ||
| Canvas tote | 312 | $29.00 |
| Backpack | 18 | $89.00 |
<div class="table-wrap">
<table class="table" data-momo-sort>
<thead><tr><th>Product</th><th class="num">Stock</th><th class="num">Price</th></tr></thead>
<tbody>
<tr class="row-group"><th colspan="3" scope="colgroup">Kitchen <span class="badge-count" data-momo-count></span></th></tr>
<tr><td>Momo Mug</td><td class="num">4</td><td class="num">$24.00</td></tr>
<tr><td>Plate set</td><td class="num">31</td><td class="num">$58.00</td></tr>
<tr><td>Tea towel</td><td class="num">120</td><td class="num">$12.00</td></tr>
<tr class="row-group"><th colspan="3" scope="colgroup">Bags <span class="badge-count" data-momo-count></span></th></tr>
<tr><td>Canvas tote</td><td class="num">312</td><td class="num">$29.00</td></tr>
<tr><td>Backpack</td><td class="num">18</td><td class="num">$89.00</td></tr>
</tbody>
</table>
</div>Colored groups
Any .bg-* class on the group row colors it: a pop color like .bg-violet (the text turns ink to stay readable) or a soft tint like .bg-cyan-soft. The same classes work on any row or single cell, and a colored row keeps its color when you hover it, in striped tables and in sticky columns.
| Task | Owner | Due |
|---|---|---|
| To do | ||
| Write the product brief | Ana | Dec 4 |
| Order packaging | Max | Dec 6 |
| In progress | ||
| New checkout | Lea | Dec 2 |
| Done | ||
| Holiday banner | Iris | Nov 28 |
| Fix card payments | Sam | Nov 27 |
<div class="table-wrap">
<table class="table table-hover" data-momo-sort>
<thead><tr><th>Task</th><th>Owner</th><th class="num">Due</th></tr></thead>
<tbody>
<tr class="row-group bg-violet"><th colspan="3" scope="colgroup">To do <span class="badge-count" data-momo-count></span></th></tr>
<tr><td>Write the product brief</td><td>Ana</td><td class="num">Dec 4</td></tr>
<tr><td>Order packaging</td><td>Max</td><td class="num">Dec 6</td></tr>
<tr class="row-group bg-yellow"><th colspan="3" scope="colgroup">In progress <span class="badge-count" data-momo-count></span></th></tr>
<tr><td>New checkout</td><td>Lea</td><td class="num">Dec 2</td></tr>
<tr class="row-group bg-green-soft"><th colspan="3" scope="colgroup">Done <span class="badge-count" data-momo-count></span></th></tr>
<tr><td>Holiday banner</td><td>Iris</td><td class="num">Nov 28</td></tr>
<tr class="bg-red-soft"><td>Fix card payments</td><td>Sam</td><td class="num">Nov 27</td></tr>
</tbody>
</table>
</div><tr class="row-group bg-violet"><th colspan="3">To do</th></tr> <!-- a pop color -->
<tr class="row-group bg-green-soft"><th colspan="3">Done</th></tr> <!-- a soft tint -->
<tr class="bg-red-soft">…</tr> <!-- any row -->
<td class="bg-yellow-soft">…</td> <!-- one cell -->Edit a cell
Add data-momo-edit to a header to make its column editable (or to one cell). Click a cell, or press Enter or F2 on it, and an input fills the whole cell. Enter or clicking away saves, Esc puts it back, Tab saves and moves to the next cell. data-momo-edit="number" gives a number field, "select" a list from data-options. A saved row blinks.
| Product | Status | Stock | Price |
|---|---|---|---|
| Momo Mug | Live | 4 | $24.00 |
| Canvas tote | Live | 312 | $29.00 |
| Sticker pack | Draft | 0 | $13.00 |
Click a cell to edit it.
<div class="table-wrap">
<table class="table" id="tbl-edit" data-momo-sort>
<thead><tr><th data-momo-edit>Product</th><th data-momo-edit="select" data-options="Draft, Live, Sold out">Status</th><th class="num" data-momo-edit="number">Stock</th><th class="num" data-momo-edit="number">Price</th></tr></thead>
<tbody>
<tr><td>Momo Mug</td><td>Live</td><td class="num">4</td><td class="num" data-format="money">$24.00</td></tr>
<tr><td>Canvas tote</td><td>Live</td><td class="num">312</td><td class="num" data-format="money">$29.00</td></tr>
<tr><td>Sticker pack</td><td>Draft</td><td class="num">0</td><td class="num" data-format="money">$13.00</td></tr>
</tbody>
</table>
</div>
<p class="text-sm text-muted mt-2" id="tbl-edit-log">Click a cell to edit it.</p>
<script>
document.getElementById('tbl-edit').addEventListener('momo:edit', function (e) {
var log = document.getElementById('tbl-edit-log');
setTimeout(function () { log.textContent = e.defaultPrevented ? 'Refused: it stays "' + e.detail.old + '".' : 'Saved: "' + e.detail.old + '" became "' + e.detail.value + '".'; });
});
</script>The field is flat by default. Add .table-edit-shadow to the table for a hard shadow on it (pages with momo-shadows on <html> get it too).
| Product | Stock |
|---|---|
| Momo Mug | 4 |
| Canvas tote | 312 |
<div class="table-wrap">
<table class="table table-edit-shadow" id="tbl-edit-shadow">
<thead><tr><th data-momo-edit>Product</th><th class="num" data-momo-edit="number">Stock</th></tr></thead>
<tbody>
<tr><td>Momo Mug</td><td class="num">4</td></tr>
<tr><td>Canvas tote</td><td class="num">312</td></tr>
</tbody>
</table>
</div>On colored tables
Editing works the same on colored headers, colored rows and stripes: the field is always a clean surface with ink text, so it reads on any color.
| Task | Status | Hours |
|---|---|---|
| Write the brief | Doing | 3 |
| Order packaging | To do | 1 |
| Fix card payments | Doing | 5 |
| Holiday banner | Done | 2 |
| Reply to leads | To do | 1 |
<div class="table-wrap">
<table class="table table-head-violet table-striped" id="tbl-edit-color">
<thead><tr><th data-momo-edit>Task</th><th data-momo-edit="select" data-options="To do, Doing, Done">Status</th><th class="num" data-momo-edit="number">Hours</th></tr></thead>
<tbody>
<tr><td>Write the brief</td><td>Doing</td><td class="num">3</td></tr>
<tr><td>Order packaging</td><td>To do</td><td class="num">1</td></tr>
<tr class="bg-yellow"><td>Fix card payments</td><td>Doing</td><td class="num">5</td></tr>
<tr class="bg-green-soft"><td>Holiday banner</td><td>Done</td><td class="num">2</td></tr>
<tr><td>Reply to leads</td><td>To do</td><td class="num">1</td></tr>
</tbody>
</table>
</div>table.addEventListener('momo:edit', (e) => {
const { cell, row, column, value, old } = e.detail;
if (!save(row.dataset.id, column, value)) e.preventDefault(); // refuse: the old value stays
});Notes
- Everything here works with the table styles: colored headers, sticky columns, sizes, stripes.
- Screen readers hear the sort order (
aria-sort), whether a row is open or folded (aria-expanded), the page buttons by number, and each editable cell's column and value. - The count under a data table is read out when you search or change page.