coverup

Table

Rows with hairline dividers, a filter box and an empty state.

Table with client-side filter

Add data-filter="#id" to an input and it hides rows that do not match. Include a <tr data-empty hidden> row for the empty state.

NameRoleStatus
Ada LovelaceAdminActive
Grace HopperEditorActive
Alan TuringViewerInvited
<div class="panel">
  <div class="panel-head">
    <div class="search"><svg class="i"><use href="#i-search"/></svg><input class="input" style="width:240px" placeholder="Filter users" aria-label="Filter users" data-filter="#people" autocomplete="off"></div>
    <button class="btn btn-primary btn-sm"><svg class="i i-sm"><use href="#i-plus"/></svg>New user</button>
  </div>
  <div class="table-scroll">
    <table class="tbl" style="min-width:480px">
      <thead><tr><th>Name</th><th>Role</th><th>Status</th></tr></thead>
      <tbody id="people">
        <tr><td><strong>Ada Lovelace</strong></td><td>Admin</td><td><span class="badge badge-ok">Active</span></td></tr>
        <tr><td><strong>Grace Hopper</strong></td><td>Editor</td><td><span class="badge badge-ok">Active</span></td></tr>
        <tr><td><strong>Alan Turing</strong></td><td>Viewer</td><td><span class="badge badge-warn">Invited</span></td></tr>
        <tr data-empty hidden><td colspan="3">No users match your filter.</td></tr>
      </tbody>
    </table>
  </div>
</div>

Server-side filter with htmx

The same box, but htmx asks the server for matching rows. This demo is answered by a mock endpoint.

NameRoleStatus
<div class="panel">
  <div class="panel-head">
    <div class="search"><svg class="i"><use href="#i-search"/></svg><input class="input" style="width:240px" name="q" placeholder="Search users" aria-label="Search users" autocomplete="off"
      hx-get="/api/users" hx-trigger="input changed delay:250ms" hx-target="#remote-users"></div>
  </div>
  <div class="table-scroll">
    <table class="tbl" style="min-width:560px">
      <thead><tr><th>Name</th><th>Role</th><th>Status</th><th></th></tr></thead>
      <tbody id="remote-users" hx-get="/api/users" hx-trigger="load"></tbody>
    </table>
  </div>
</div>

Classes

SelectorPurpose
.tblTable
.table-scrollWrapper that scrolls sideways on small screens
tr[data-empty]Empty-state row
[data-filter="#tbody"]On an input, filters that tbody client-side