Skip to content
Focsd homeFocsd homeFocsd
Forms

Data grid

A data grid with sorting, search, typed filters, pinning, resizing, reordering, grouping, editing and export.

  • Tag: focsd-data-grid
  • Pattern: Grid (sort, filter, paginate, virtualize)
  • Category: Data

Example

HTML
<div class="full">
<focsd-data-grid
id="grid-demo"
label="Invoices"
page-size="8"
selection="multiple"
quick-search
toolbar></focsd-data-grid>
</div>
<script type="module">
const grid = document.getElementById('grid-demo');
grid.columns = [
{ id: 'id', header: 'Invoice', type: 'number', pinned: 'start', width: 112, formatOptions: { useGrouping: false } },
{ id: 'customer', header: 'Customer', editable: true, required: true },
{ id: 'owner', header: 'Owner', display: 'avatar' },
{ id: 'status', header: 'Status', type: 'enum', editable: true,
options: [
{ value: 'paid', label: 'Paid', tone: 'positive', icon: 'check' },
{ value: 'sent', label: 'Sent', tone: 'info' },
{ value: 'overdue', label: 'Overdue', tone: 'critical', icon: 'alert-circle' },
{ value: 'draft', label: 'Draft' },
] },
{ id: 'region', header: 'Region', type: 'enum', editable: true,
options: [{ value: 'eu', label: 'Europe' }, { value: 'us', label: 'Americas' }, { value: 'ap', label: 'Asia Pacific' }] },
{ id: 'amount', header: 'Amount', type: 'number', aggregate: 'sum', editable: true, min: 0,
formatOptions: { style: 'currency', currency: 'EUR' } },
{ id: 'due', header: 'Due', type: 'date', aggregate: 'max', editable: true },
];
const customers = ['Northwind', 'Contoso', 'Fabrikam', 'Tailspin', 'Wingtip', 'Adatum'];
const owners = ['Amara Okafor', 'Lukas Brandt', 'Priya Raman', 'Tomás Herrera', 'Mei Lin'];
grid.rows = Array.from({ length: 40 }, (_, i) => ({
id: 1001 + i,
customer: customers[i % customers.length],
region: ['eu', 'us', 'ap'][i % 3],
amount: ((i * 7919) % 9000) + 120,
due: '2026-' + String((i % 12) + 1).padStart(2, '0') + '-' + String((i % 27) + 1).padStart(2, '0'),
owner: owners[i % owners.length],
status: ['paid', 'sent', 'overdue', 'draft', 'paid'][i % 5],
}));
</script>

Usage

Import the module once, then use the tag like any HTML element. Every framework below renders the same element; see Frameworks for setup.

<script type="module">
import '@focsd-dev/data-grid';
</script>
<focsd-data-grid label="Invoices" page-size="8" selection="multiple" quick-search toolbar></focsd-data-grid>

API

Attributes

AttributePropertyTypeDefault
labellabelstring—
page-sizepageSizenumber25
selectionselection'none' | 'single' | 'multiple'none
densitydensityGridDensitycomfortable
localelocalestring—
externalexternalbooleanfalse
row-countrowCountnumber0
loadingloadingbooleanfalse
quick-searchquickSearchbooleanfalse
toolbartoolbarbooleanfalse

JavaScript properties

PropertyTypeDescription
columns{ id, field, header, type, display, width, minWidth, maxWidth, pinned, hidden, sortable, filterable, resizable, editable, groupable, searchable, aggregate, formatOptions, options, labels, render, validate, required, min, max, valueGetter, valueSetter }[]Column definitions. type is text, number, date, boolean or enum (with options), or a type added with registerType(). An enum option with tone, color or icon shows its values as status chips; display: 'avatar' shows names with an avatar.
rowsobject[]Row objects. Edits replace rows immutably, so keep your own copy in sync from focsd-cell-edit.
rowIdstring | (row) => idField or function giving a stable row id (default id). Needed for selection and editing.
selectedIdsunknown[] (read-only)Ids of the selected rows.

Methods

MethodDescription
getState()The view as JSON: column order, visibility, widths and pinning; sort; filters; search; grouping and expanded groups; page and page size; density.
setState(state)Restore a saved view. Unknown columns and invalid filters are ignored.
exportCsv({ selectedOnly, raw })CSV of the filtered, sorted, visible view (or the selection), with formula-injection protection.
downloadCsv(filename, options)Download that CSV (options as for exportCsv). The file name defaults to the label.
setGroupBy(columnIds)Group rows by these columns, outermost first.
expandAll() / collapseAll()Open or close every group.
startEditing(rowId, columnId)Move to a cell and start editing it.
scrollToRow(rowId)Bring a row into view (changing page if needed) and focus it in the active column.

CSS parts

Style the inside of the component with ::part(), for example focsd-data-grid::part(grid).

PartDescription
gridThe scrolling grid element.
rowA data row.
cellA data cell.
pagination-pagePagination parts, re-exported with a `pagination-` prefix (pagination-nav, pagination-list, pagination-page, pagination-previous, pagination-next, pagination-gap).
header-rowThe header row.
header-cellA column header.
footerThe footer with paging and counts.

Accessibility

  • APG grid (or treegrid when grouped) with aria-rowcount, aria-colcount, aria-rowindex and aria-colindex that stay correct under paging, windowing, pinning and hidden columns.
  • One tab stop for all cells. Pinned columns are sticky cells inside each row, so every row is still one row to assistive technology.
  • Sorting, filtering, grouping, selection, edits and column changes are announced in a polite live region ("Sorted by Amount, descending", "Filter applied: Region is Europe. 14 of 40 rows").
  • Every pointer gesture has a keyboard path: the column menu resizes (Widen, Narrow, Autosize), pins and hides; the Columns panel shows, hides and reorders.
  • Editors are labeled ("Edit Amount"); invalid input keeps the editor open with an error that is described and announced.

Keyboard

KeyAction
Arrow keysMove between cells
Home / EndFirst / last cell in the row
Ctrl + Home / EndFirst / last cell in the grid
Page Up / DownPrevious / next page, or a screen of rows when not paginated
Enter (header)Sort; Shift + Enter adds to the sort
Alt + Arrow Down / Shift + F10 / Menu (header)Open the column menu
SpaceSelect the row; Shift + Space selects a range
Ctrl / ⌘ + ASelect all rows (selection="multiple")
Enter / F2 / typingEdit the cell (Enter saves and moves down, Tab saves and moves sideways, Escape cancels)
Enter (read-only cell)Fire focsd-row-activate
Enter / Space / Arrow Right / Arrow Left (group row)Toggle, expand or collapse the group (arrows in the first column)