DataTable <pm-data-table>
Advanced data table for business apps: search, filters, sorting, frozen columns, selection, grouping, editing and export.
Overview
Everything is optional and driven by column definitions:
- Find: global search box (
searchable), per-column filters (text, select, number ranges), multi-column sort (Shift+click adds a sort level). - Columns: freeze (
pin: 'start' | 'end'), resize (drag or keyboard), reorder (drag headers or the column menu), show/hide (column-picker), header groups (group), and a per-column actions menu. - Rows: single or multi selection (Shift+click for ranges, "select all N" across pages), pinned rows that stay on top (
pinned-rows), expandable detail rows (expandable+renderDetail), grouping with counts (group-by), merged cells (merge→ rowspan,colSpan→ colspan), inline editing. - Data: client-side paging or
manualfor server-side (events carry the full query), footer aggregates (sum/avg/min/max/count), Intl formatting bytype, CSV export (exportable/toCsv()), infinite loading (pm-end-reached), saved views (state,persist). - Use: spreadsheet-style keyboard grid (arrows, Home/End, PageUp/Down, Enter/F2 to edit, Space to select), sticky header and footer, loading bar, labelled cards in narrow containers, every UI string replaceable.
- Content: per column
render(row)(text, DOM node or Lit template), light-DOM<template data-cell="key">with escaped{{field}}placeholders,format(value, row), or Intl formatting bytype(number, currency, percent, bytes, date, datetime, time, boolean) withformatOptionsandprefix/suffix. Headers the same way:renderHeader(col)or<template data-header="key">;labelstays the accessible and CSV name.
Server-side data: set src to a URL (src="/api/orders"; the query goes in as q, page, pageSize, sort, order, sorts and filter[key] parameters, or as {placeholders} in the URL) and say where the rows and the total are in the JSON (rows-path="data", total-path="meta.total"), or set the loader property to your own async (query, { signal }) => ({ rows, total }). mapRow formats each server row. Searching, sorting, filtering and paging then reload from the server (search debounced by debounce), superseded requests are cancelled, and loading and error (with Retry) states show. reload() fetches the current page again.
Columns and rows can be properties or JSON attributes (columns='[{"key":"name","label":"Name","sortable":true}]'). For a light table without these features use <pm-table>.
Attributes
| Attribute | Type | Default | Description |
|---|---|---|---|
columns | DataTableColumn<R>[] | [] | Column definitions: key, label, type, sorting, filters, pinning, grouping, merging, editing and rendering. |
rows | R[] | [] | Row objects (or a JSON string). In manual mode, the current page from your server. |
label | string | — | Accessible name (caption). |
row-keyprop: rowKey | string | id | Field that identifies a row (default "id", else its position). |
stack | 'auto' | 'never' | — | Narrow containers (< 36rem): auto shows rows as labelled cards; never keeps a horizontally scrolling table. |
selectable | boolean | false | Show row checkboxes (see selection for single or multiple). |
selection | 'single' | 'multiple' | — | multiple (default, checkboxes) or single (radio buttons). |
filter | string | — | Global search text (matches any visible column, raw or formatted). |
page-sizeprop: pageSize | number | 0 | Rows per page (0 = no paging). |
page | number | 1 | Current page, starting at 1. |
total | number | — | Total rows on the server (with manual). |
manual | boolean | false | Rows are already sorted, filtered and paged by the server: render them and emit events with the query. |
loading | boolean | false | Show a loading state (and mark the region busy for assistive tech). |
striped | boolean | false | Shade alternate rows. |
empty-textprop: emptyText | string | — | Text shown when there is nothing to list. |
row-clickableprop: rowClickable | boolean | false | Emit pm-row-click and show a pointer on rows. |
searchable | boolean | false | Show a search box in the toolbar. |
column-pickerprop: columnPicker | boolean | false | Show a Columns menu to show, hide and reset columns. |
exportable | boolean | false | Show an Export CSV button. |
column-menuprop: columnMenu | boolean | true | Per-column actions menu in each header (default on; column-menu="false" to hide). |
group-byprop: groupBy | string | — | Group rows by this column key (collapsible group headers with counts). |
expandable | boolean | false | Add a toggle that shows renderDetail(row) under the row. |
pinned-rowsprop: pinnedRows | string[] | [] | Row keys pinned to the top (always visible, stay under the header while scrolling). |
locale | string | — | BCP 47 locale for number/date formatting. |
max-heightprop: maxHeight | string | — | Scroll inside the table past this height, e.g. "28rem" (sticky header and footer). Rows that would overflow it by less than a wheel notch are shown whole instead (a sliver of inner scroll catches the wheel); not in the narrow card layout, where cards flow with the page. |
persist | string | — | Save the user's view (columns, sort, filters) in localStorage under this key. |
page-sizesprop: pageSizes | number[] | — | Rows-per-page choices shown in the footer, e.g. [10, 25, 50]. |
src | string | — | Server URL for rows; the query is added as parameters (or fills {placeholders}). Response: JSON. Implies manual. |
rows-pathprop: rowsPath | string | — | Where the rows are in the response (dotted path; default: the response if it is an array, else rows, data or items). |
total-pathprop: totalPath | string | — | Where the total row count is in the response (dotted path; default total, then count). |
debounce | number | 300 | Milliseconds to wait after typing in search or filters before asking the server. |
Also accepts the contextual attributes tone, surface, radius, density, motion, elevation. They are inherited from ancestors' data-* attributes.
Events
| Event | React / Svelte prop | Description |
|---|---|---|
pm-sort | onPmSort | The sort order changed. detail.sorts is the whole sort order. |
pm-filter | onPmFilter | Search or column filters changed. |
pm-selection-change | onPmSelectionChange | The selected rows changed. |
pm-page | onPmPage | The page or the page size changed. |
pm-row-click | onPmRowClick | A row was clicked (with row-clickable). |
pm-expand | onPmExpand | A row's detail was opened or closed. |
pm-cell-edit | onPmCellEdit | A cell was edited. Cancelable (call preventDefault to reject). |
pm-state-change | onPmStateChange | Column layout, sort or filters changed. |
pm-column-resize | onPmColumnResize | A column was resized by its handle (key, width in px), to save it. |
pm-load | onPmLoad | Server rows arrived. |
pm-load-error | onPmLoadError | A server request failed. |
pm-end-reached | onPmEndReached | Scrolled near the bottom (load more rows). detail.rows is how many are loaded. |
Slots
| Slot | Description |
|---|---|
empty | Content when there are no rows. |
toolbar | Extra content in the toolbar (filters, bulk actions). |
Methods
reload(), resetColumns(), selectAllMatching(), clearSelection(), moveColumn(), pinColumn(), setColumnVisible(), pinRow(), toggleRow(), toCsv(), exportCsv()
Used in templates
Overview dashboardTraffic analyticsOrdersCustomer 360Project boardTeam and rolesBilling and invoices