An accessible Etch table shell with:

  • a Columns repeater for headings and behavior;
  • a Rows slot for the loop and row markup;
  • independent search, stable sorting, and client-side pagination per instance;
  • a Table style class prop with editable nested CSS.

The loop belongs in the Rows slot. This keeps Etch’s normal loop context
available to every element in the row, so cells may contain links, images,
spans, SVG, Raw HTML, conditions, and complete dynamic expressions such as:

{item.date.dateFormat("F j, Y")}

Component props

LabelKeyTypeDefault
Table styletableStyleClassetch-data-table
ColumnscolumnsGroup with Repeater enabledInstance column definitions
CaptioncaptionTextPosts
Enable searchenableSearchBooleantrue
Search labelsearchLabelTextSearch posts
Search placeholdersearchPlaceholderTextEmpty
Enable paginationenablePaginationBooleantrue
Rows per pagepageSizeText10
Rows per page labelrowsPerPageLabelTextRows per page
Custom rows optioncustomPageSizeTextEmpty
Pagination labelpaginationLabelTextPosts table pagination
Previous labelpreviousLabelTextPrevious
Next labelnextLabelTextNext
No results textnoResultsTextTextNo matching results.

pageSize is a Text prop because Etch does not currently expose a number prop.
The built-in selector options are 10, 20, 50, 100, and All. Enter a
positive whole number in customPageSize to add one custom option. The script
validates both props and falls back to 10.

Columns repeater

LabelKeyTypeOptions/default
HeadingheadingTextColumn label
SortablesortableBooleanfalse
SearchablesearchableBooleantrue
Sort typesortTypeSelectauto, text, number, or date
Header scopeheaderScopeSelectcol or colgroup

Keep the repeater’s component-level default empty. Etch stores each instance’s
column rows in its encoded bracket format. A native array here can trigger the
builder’s e.startsWith is not a function error.

Rows slot

Place an Etch Loop inside the rows slot, then build one semantic row template
inside that loop:

<tr>
  <th scope="row">
    <a href="{item.permalink.relative}">{item.title}</a>
  </th>
  <td>{item.author.displayName}</td>
  <td data-table-sort-value="{item.date.dateFormat("Y-m-d H:i:s")}">
    {item.date.dateFormat("F j, Y")}
  </td>
  <td><!-- any Etch elements, including Raw HTML --></td>
</tr>

The body row is deliberately manual. The component does not attempt to resolve
arbitrary dynamic expressions from repeater strings, which preserves all Etch
dynamic-data modifiers and avoids crossing component/repeater scope boundaries.

The row author is responsible for:

  • using the same number and order of cells as the Columns repeater;
  • using <th scope="row"> where a cell identifies its row;
  • using <td> for normal data cells;
  • keeping interactive content keyboard accessible.

Optional cell attributes:

  • data-searchable="true|false" overrides the corresponding column setting;
  • data-table-search-value="..." supplies alternate searchable text;
  • data-table-sort-value="..." supplies a normalized sort value.

For formatted dates, show the human-readable date in the cell and provide an
ISO-like value through data-table-sort-value.

Styling

The root uses {props.tableStyle}. Its default class is
.etch-data-table, whose CSS body is in
component-style.css.

The file is nested CSS intended for Etch’s class CSS editor. It exposes local
--table-* variables and maps them to Automatic.css variables with fallbacks,
including spacing, colors, borders, radii, focus styles, and button styles.
Override the variables or replace the class through the Table style prop.
JavaScript behavior is attached through data-* hooks, not the default class,
so a replacement style class does not disable the table.

JavaScript behavior

component.js:

  • initializes every [data-etch-data-table] independently;
  • guards against duplicate initialization;
  • observes instances inserted after page load;
  • searches only enabled columns;
  • performs stable sorting and maintains aria-sort;
  • paginates the filtered result set;
  • updates a polite live region after search, sorting, and page changes.

Search and pagination are client-side. The loop must render the complete set
that visitors should be able to search and sort.

Required loop query size

Set the Posts loop query to:

posts_per_page => -1

The table does not request a new WordPress query for each client-side page.
It searches, sorts, and paginates only the rows already rendered into the
table. A query limit such as 10 would therefore make later WordPress posts
unavailable to the table. The installed Posts loop uses
$limit ?? -1, and this table instance does not pass a limit, so its effective
value is -1.

This does not interfere with the table’s pagination: WordPress renders the
complete result once, and the component JavaScript shows the selected number
of rows per page.

Pagination pattern

The pagination follows the
U.S. Web Design System pagination pattern:

  • a descriptive <nav> containing an unordered list;
  • first, previous, current-neighbor, last, and next navigation;
  • non-interactive ellipses wherever page ranges are omitted;
  • aria-current="page" on the active numbered button;
  • explicit labels such as Page 3 and Last page, page 12;
  • inline, decorative SVG chevrons for Previous and Next;
  • one non-wrapping row of generously sized controls.

The rows-per-page selector sits at the start of the controls row and pagination
sits at the opposite end. On narrow screens the groups wrap as units while the
pagination items themselves remain on one line.