Datatable
Styling — this component renders in the light DOM
It has no shadow root. Anything you render into it — row templates, node templates, cell renderers — stays in the document, so your app's stylesheet, your own component styles and Bootstrap's utility classes reach it normally.
Its own CSS is scoped at build time onto a data-mps attribute, the same device Angular uses for _ngcontent, so it cannot leak out onto your markup.
The trade-off runs the other way: page CSS now reaches this component's internals, exactly as emulated encapsulation behaves everywhere else.::part() and ::slotted() no longer address it — use ordinary CSS selectors instead.
Simple in-memory table
| Radiohead | Alternative | 1985 |
| Daft Punk | Electronic | 1993 |
| Tame Impala | Psychedelic | 2007 |
| Pink Floyd | Progressive | 1965 |
<BsDatatable columns={COLUMNS} data={ARTISTS} />Column resizing
Drag the line at the right edge of a header, or focus it and use the keyboard. A tap or click on it, without dragging, opens the resize options instead.
- Tab reaches each column's resize handle.
- ← / → make the column 10 px narrower or wider.
- Enter opens the resize options: narrower, wider, fit to content, reset. Esc closes them.
| Radiohead | Alternative | |
| Daft Punk | Electronic | |
| Tame Impala | Psychedelic | |
| Pink Floyd | Progressive |
const RESIZE_COLUMNS: DatatableColumnDef[] = [ { name: 'name', label: 'Name' }, { name: 'genre', label: 'Genre' }, // Icon-only header: label names it; resizable: false drops its handle. { name: 'actions', label: 'Actions', sortable: false, resizable: false },];<BsDatatable columns={RESIZE_COLUMNS} data={ARTISTS} header={({ column }) => column.name === 'actions' ? <span aria-hidden="true">⋯</span> : column.label} cell={({ row, column, rowIndex }) => column.name === 'actions' ? <button type="button" className="btn btn-sm btn-outline-secondary">Details</button> : cellText(row, column, rowIndex)}/>Fit a sized parent
With fill the table fits a parent with a fixed height, such as a dashboard tile. The header stays at the top and the pagination at the bottom; only the rows scroll in between. Horizontally the whole table scrolls as one.
| Radiohead | Alternative | 1985 |
| Daft Punk | Electronic | 1993 |
| Tame Impala | Psychedelic | 2007 |
| Pink Floyd | Progressive | 1965 |
| Radiohead | Alternative | 1985 |
| Daft Punk | Electronic | 1993 |
| Tame Impala | Psychedelic | 2007 |
| Pink Floyd | Progressive | 1965 |
| Radiohead | Alternative | 1985 |
| Daft Punk | Electronic | 1993 |
| Tame Impala | Psychedelic | 2007 |
| Pink Floyd | Progressive | 1965 |
| Radiohead | Alternative | 1985 |
| Daft Punk | Electronic | 1993 |
| Tame Impala | Psychedelic | 2007 |
| Pink Floyd | Progressive | 1965 |
| Radiohead | Alternative | 1985 |
| Daft Punk | Electronic | 1993 |
| Tame Impala | Psychedelic | 2007 |
| Pink Floyd | Progressive | 1965 |
// The parent needs a definite height.<div style={{ height: 225 }}> <BsDatatable fill pagination perPage={20} columns={COLUMNS} data={rows} /></div>fill combines with virtualScroll: the parent's height replaces the default virtual viewport, and only the rows in view are rendered.
| Radiohead | Alternative | 1985 |
| Daft Punk | Electronic | 1993 |
| Tame Impala | Psychedelic | 2007 |
| Pink Floyd | Progressive | 1965 |
| Radiohead | Alternative | 1985 |
| Daft Punk | Electronic | 1993 |
| Tame Impala | Psychedelic | 2007 |
| Pink Floyd | Progressive | 1965 |
| Radiohead | Alternative | 1985 |
| Daft Punk | Electronic | 1993 |
| Tame Impala | Psychedelic | 2007 |
| Pink Floyd | Progressive | 1965 |
| Radiohead | Alternative | 1985 |
| Daft Punk | Electronic | 1993 |
| Tame Impala | Psychedelic | 2007 |
| Pink Floyd | Progressive | 1965 |
| Radiohead | Alternative | 1985 |
| Daft Punk | Electronic | 1993 |
| Tame Impala | Psychedelic | 2007 |
| Pink Floyd | Progressive | 1965 |
| Radiohead | Alternative | 1985 |
| Daft Punk | Electronic | 1993 |
| Tame Impala | Psychedelic | 2007 |
| Pink Floyd | Progressive | 1965 |
| Radiohead | Alternative | 1985 |
| Daft Punk | Electronic | 1993 |
| Tame Impala | Psychedelic | 2007 |
| Pink Floyd | Progressive | 1965 |
| Radiohead | Alternative | 1985 |
| Daft Punk | Electronic | 1993 |
| Tame Impala | Psychedelic | 2007 |
| Pink Floyd | Progressive | 1965 |
// The parent's height replaces the default virtual viewport.<div style={{ height: 225 }}> <BsDatatable fill virtualScroll itemSize={40} columns={COLUMNS} data={rows} /></div>Virtual scrolling — lazy windowed fetch
Set one fetch callback and the web component owns the whole loop: it loads page 1, derives the total from the response, and fetches each window only as its rows scroll into view. This list is the 1000 seeded orders from apps/api; scroll it and watch the fetch log — it never drains every page. No totalRecords prop, no event bridge.
Pages fetched: — (0 so far)
| Loading… | |||
// One callback. The table owns page 1, every window, the total, and the scrollbar.const fetchOrders = useCallback( async (req: DatatableFetchRequest): Promise<DatatableFetchResponse<Order>> => { const res = await api.searchOrders(req.page, req.perPage, req.sortColumns); return { data: res.items, totalRecords: res.totalCount }; }, []);<BsDatatable columns={ORDER_COLUMNS} fetch={fetchOrders} virtualScroll itemSize={40} perPage={25} />Row selection — checkbox mode
With selectionMode="checkbox" a row click only opens the row (onRowClick); selecting happens in the checkbox cell alone. The selection is keyed by rowKey — which must be stable with fetch — so it survives paging and sorting: tick a row, change page, and the count keeps it. rowLabel names each checkbox for assistive technology.
Selected 0 order(s) · Opened: —
| Loading… | ||||
Keyboard, rows: ↑/↓ move between rows; →/← expand/collapse a tree row. In checkbox mode Enter opens the row and Space toggles its checkbox. In the default multiple mode Enter or Space selects the row and then opens it, with Ctrl toggling and Shift selecting a range — the same modifiers as a click.
<BsDatatable columns={ORDER_COLUMNS} fetch={fetchOrders} // stable: module-level or useCallback perPage={10} selectionMode="checkbox" // row click opens; the checkbox cell selects rowKey={(row) => String(row.id)} // stable identity, required with fetch rowLabel={(row) => `order #${row.id}`} // "Select order #12" onRowClick={(d) => setOpened(d.row)} onSelectedIdsChange={setSelectedIds}/>Tree mode — expandable rows
The same single fetch callback, branching on req.parentId for roots vs. children. The WC paginates roots lazily and loads children on expand; selected row objects arrive on onSelectionChanged as detail.selectedRows.
| Loading… | ||||
// Same single callback; it branches on req.parentId for roots vs children.// The WC lazily paginates roots AND loads children on expand.const fetchTree = useCallback( async (req: DatatableFetchRequest): Promise<DatatableFetchResponse<TreeItem>> => { const r = await treeApi.list(req.parentId, req.page, req.perPage); return { data: r.items, totalRecords: r.totalCount }; }, []);<BsDatatable columns={TREE_COLUMNS} fetch={fetchTree} virtualScroll itemSize={40} tree idKey="id" childCountKey="childCount" selectionMode="multiple" selectionStrategy="cascading" onSelectionChanged={(d) => setSelected(d.selectedRows)}/>Column filters
Mark a column filterable and the table grows a second header row with a dropdown trigger in that column. Columns without it get an empty, correctly-sized cell, so the row stays aligned. Drop them all and the row is not rendered at all — toggle the checkbox to see it.
A filterable column gets a built-in panel for free: a search box, an include/exclude toggle, a checkbox list of the column's distinct values, and a clear button. It lives in the shared core, so there is no React code behind it at all — the Name column below just sets filterable, with its values listed by the server (distincts).
A checkbox list is the wrong question for a quantity, so a column can ask a different one: filterMode: 'comparison' renders an operator (=, ≠, <, ≤, >, ≥) and a single input, with filterInputType choosing number (the default), date (a calendar day) or datetime (local time in, a UTC instant out) — the Created column below. Still the built-in panel: no slot, no styling of your own. Narrow the list with filterOperators when only some operators make sense.
Quantities only — there is no text input type and no contains operator. Comparing strings is either exact match, which the value list already does better, or a lexicographic >, which is almost never what anyone means. A free-text filter is a nest-your-own case, below.
You pick the mode per column and the component never infers it: a numeric column is often an enum and a string column is often ordinal, so any guess would be wrong about half the time.
When neither built-in question fits, set filterMode: 'custom' on the column and render the panel in the table's filter slot — Country does. The slot receives the column and a context with the loaded values and the search, apply and clear commands. That markup is yours, so you style it — Bootstrap's .form-control is only styled inside bs-* components here.
The panel is a native popover in the top layer, so it is not clipped by the scroll container and not hidden behind the sticky header.
Filtering happens on the server. The table keeps the active filters in a two-way filters / onFiltersChange model and sends them, with your own fetchParams, in every fetch and distincts request; it never filters rows itself. With stateKey and an MpTransferStateProvider, the server render fetches the first page and the browser hydrates with it.
Because the browser skips fetch for that first page, anything else your fetch reads off its response (the columns a server query decides, say) belongs in the response's extra, which must be JSON. onPageLoad hands it back for every page the table applies, with seeded: true for the page that came from the server. Record it in fetch too: onPageLoad fires in the browser only.
The table owns the filter state. A panel is created on its first open and kept after that, so what you ticked, typed or scrolled to is still there when you reopen it — also when new rows arrive, because the value list is keyed by value. A write to filters from outside updates the ticks in place (and re-lists an open panel's values). Pass it without onFiltersChange and set filtersReadonly, and the page can still set filters while the panels open with their controls disabled.
Keyboard: Tab reaches each trigger, Enter/Space opens the panel and moves focus to its search box, Tab cycles inside it, Esc closes and returns focus to the trigger. Clearing a filter moves focus back to the search box, because the clear button disables itself.
| Customer 0002 | customer0002@example.com | BE | 19 Dec 2024, 16:58 UTC |
| Customer 0003 | customer0003@example.com | BE | 5 Sept 2025, 16:58 UTC |
| Customer 0005 | customer0005@example.com | BE | 24 Apr 2024, 16:58 UTC |
| Customer 0006 | customer0006@example.com | NL | 10 Sept 2025, 16:58 UTC |
| Customer 0008 | customer0008@example.com | NL | 7 Sept 2025, 16:58 UTC |
| Customer 0011 | customer0011@example.com | NL | 24 Dec 2025, 16:58 UTC |
| Customer 0012 | customer0012@example.com | BE | 19 Jun 2024, 16:58 UTC |
| Customer 0014 | customer0014@example.com | BE | 13 Jun 2024, 16:58 UTC |
| Customer 0015 | customer0015@example.com | BE | 1 Dec 2023, 16:58 UTC |
| Customer 0017 | customer0017@example.com | BE | 14 Apr 2026, 16:58 UTC |
{"country":{"values":["BE","NL"],"inverse":false}}// The table owns the filter UI and the filters model; the SERVER filters.const [filters, setFilters] = useState<DatatableFilters>({ Country: { values: ['BE', 'NL'], inverse: false },});const [search, setSearch] = useState('');const columns: DatatableColumnDef[] = [ // A checkbox list of the column's distinct values, from `distincts`. { name: 'name', filterable: true }, { name: 'country', filterable: true, filterMode: 'custom' }, // Local time in the box, a UTC instant on the wire. { name: 'createdAt', filterable: true, filterMode: 'comparison', filterInputType: 'datetime', filterOperators: ['gte', 'lt'] },];// The API takes { page, perPage, sortColumns, filters, params } as-is.const fetchCustomers: DatatableFetch<Customer, Params> = ({ signal, ...req }) => postJson('/api/customers/table', req, signal);// Faceted: computed over the OTHER columns' filters.const distincts = ({ signal, ...req }: DistinctsRequest<Params>) => postJson<DistinctValues>('/api/customers/distincts', req, signal);// stateKey + <MpTransferStateProvider> in the entries: the server render// fetches page 1 and the browser hydrates with it, fetching nothing.<BsDatatable pagination stateKey="customers" columns={columns} fetch={fetchCustomers} distincts={distincts} filters={filters} onFiltersChange={setFilters} fetchParams={{ search }} filter={({ ctx }) => ( <button type="button" onClick={() => ctx.apply(BENELUX, false)}>Benelux</button> )} />