Modules
Everything beyond "a table with columns" is a module: saved state, the column menu, filters, selection, row actions, export, summaries, toolbar buttons — and the data sources themselves. A module is an immutable definition created by a factory function (colVis(), excel({ … })) and attached with use. The same definition can be shared by many grids; each grid binds its own copy when it is created.
import { Datagrid, serverSide, yajra, colVis, stateSave, excel } from "@akinozgen17/datagrids";
new Datagrid("#agents", {
label: "Field agents",
columns: [{ key: "name", title: "Name" }],
use: [serverSide({ url: "/api/agents", protocol: yajra(), csrf: true }), colVis(), stateSave(), excel()],
});(String columns on yajra grids are plain { key, title } objects: the server already escapes the values — see Server protocols.)
Modules are separate exports, so a bundler drops the ones you never import (tree-shaking). Read Concepts → Modules for the mental model; this page is the catalog.
Catalog
Each module's API is added to the grid under the name in the "Grid API" column (grid.state.reset(), grid.selection.payload()). In TypeScript, grid.module(stateSave) returns the typed API.
| Module | Import | What it does | Grid API | Pipelines |
|---|---|---|---|---|
| stateSave | stateSave() | Remembers sort, page size, hidden columns | state | state |
| colVis | colVis() | Show / hide columns menu | colVis | toolbar |
| colReorder | colReorder() | Drag or move columns | colReorder | header, state |
| multiSort | multiSort() | Shift+click sorts by several columns | multiSort | header |
| columnFilters | columnFilters() | Typed filter in each header | columnFilters | filters, toolbar |
| filterPanel | filterPanel() | Binds your own filter form | filterPanel | request, filters |
| urlSync | urlSync() | View state in the query string | urlSync | lifecycle |
| responsive | responsive() | Collapse columns on narrow screens | responsive | render, header |
| lazyColumns | lazyColumns() | Request costly columns only when visible | lazyColumns | request |
| stickyHeader | stickyHeader() | Header stays visible while the page scrolls | stickyHeader | lifecycle |
| filterPresets | filterPresets() | Named filter chips | filterPresets | filters, toolbar, state |
| autoRefresh | autoRefresh() | Silent reload on an interval | autoRefresh | toolbar, lifecycle |
| softDeletes | softDeletes() | "Show deleted" toggle | softDeletes | request, row, toolbar |
| actions | actions() | Row buttons and ⋯ menu | actions | row |
| selection | selection() | Checkboxes, select all, bulk bar | selection | row |
| rowReorder | rowReorder() | Drag or keyboard-move rows, save in onEnd | rowReorder | row |
| keyboardGrid | keyboardGrid() | Arrow-key cell navigation, one tab stop | keyboardGrid | lifecycle |
| excel | excel() | .xlsx download | excel | toolbar, export |
| csv | csv() | .csv download | csv | toolbar, export |
print() | Print view (and PDF) | print | toolbar, export | |
| footer | footer() | Summary row in <tfoot> | footer | render, export |
| metaBind | metaBind() | Response fields → page elements | metaBind | render |
| button.reload | button.reload() | Reload button | reloadButton | toolbar |
| button.resetState | button.resetState() | Reset the saved view | resetStateButton | toolbar |
| button.custom | button.custom() | Your own toolbar button | its name | toolbar |
| button.group | button.group() | Toolbar dropdown | its name | toolbar |
Pipelines: request = request middleware (adds parameters to server requests) · filters = writes the grid's filter state, which the protocol encodes · row = row mutator (runs after each row renders) · toolbar = toolbar slot · state = saved-state contribution · export = feeds the export sheet · render = repaints after each render · header = decorates the header row · lifecycle = init / load / destroy hooks.
Data sources (serverSide, arraySource, domSource, fetchAll, customSource) are modules too, with exactly one per grid — see Data sources.
Toolbar order
Toolbar modules place themselves in a named slot with an order (lower first). colVis, the button.* modules, softDeletes, autoRefresh and filterPresets accept slot and order to move them. The shared Export menu (start, 40) moves with slot / order on the first export module attached (excel({ slot: "end" })); the column filter chips (filters, 100) have a fixed place.
| Slot | Default contents (order) |
|---|---|
start | search box (0) · colVis (10) · button.reload (20) · button.resetState (30) · Export menu (40) · button.custom (50) · button.group (60) |
end | autoRefresh (−20) · softDeletes (−10) · record count (count: true, 0) |
filters | filterPresets (−20) · columnFilters chips (100) |
Presets
A preset is just an array of modules. Put your house standard in one function and every list page becomes one line; arrays nest, so a preset can be mixed with page-specific modules.
import { serverSide, yajra, colVis, button, stateSave, excel, print } from "@akinozgen17/datagrids";
export const listPage = (url) => [
serverSide({ url, protocol: yajra(), csrf: true }),
colVis(),
button.reload(),
stateSave(),
excel(),
print(),
];import { Datagrid, column, serverSide, yajra, colVis, button, stateSave, excel, print } from "@akinozgen17/datagrids";
import { statusLabels, statusTones } from "./data.js";
// one array = one house standard for every list page
const listPage = (url) => [
serverSide({ url, protocol: yajra(), csrf: true }),
colVis(),
button.reload(),
stateSave(),
excel(),
print(),
];
new Datagrid("#mod-preset", {
label: "Field agents (preset)",
columns: [
{ key: "ref", title: "Ref" },
{ key: "name", title: "Name" },
{ key: "unit", title: "Unit" },
column.badge("status", { title: "Status", labels: statusLabels, tones: statusTones }),
column.money("amount", { title: "Amount", currency: "USD", locale: "en-US" }),
],
pageSize: 10,
use: [listPage("/api/agents")],
});<table id="mod-preset"></table>Add page-specific modules next to it: use: [listPage("/api/agents"), selection()]. For declarative markup (table[data-datagrid="list"]), register the same array with preset().
Permission flag can
Every module accepts can. With can: false the module is still attached (so code that calls its API keeps working — the calls do nothing) but it contributes nothing: no button, no menu item, no request parameter, no state.
use: [
serverSide({ url: "/api/agents", protocol: yajra(), csrf: true }),
excel({ can: user.canExport }),
softDeletes({ can: user.isAdmin }),
];- Columns take the same flag: a column with
can: falsedoes not exist at all — it is not rendered, not in the column menu, not exported, not saved in state and not sent to the server. - Row actions are the only place where
canmay be a function of the row:{ id: "delete", can: (row) => row.status !== "done" }. See actions. canis a UX flag. Your endpoints must still authorize every request.
Module rules
- One instance per module per grid: attaching the same module twice throws DG009; two data sources throw DG008.
- A module that depends on another (
button.resetState→stateSave) throws DG007 when the dependency is missing. - Request middleware runs in attach order. See Writing a module for the full module contract.