Skip to content

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.

js
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.

ModuleImportWhat it doesGrid APIPipelines
stateSavestateSave()Remembers sort, page size, hidden columnsstatestate
colViscolVis()Show / hide columns menucolVistoolbar
colReordercolReorder()Drag or move columnscolReorderheader, state
multiSortmultiSort()Shift+click sorts by several columnsmultiSortheader
columnFilterscolumnFilters()Typed filter in each headercolumnFiltersfilters, toolbar
filterPanelfilterPanel()Binds your own filter formfilterPanelrequest, filters
urlSyncurlSync()View state in the query stringurlSynclifecycle
responsiveresponsive()Collapse columns on narrow screensresponsiverender, header
lazyColumnslazyColumns()Request costly columns only when visiblelazyColumnsrequest
stickyHeaderstickyHeader()Header stays visible while the page scrollsstickyHeaderlifecycle
filterPresetsfilterPresets()Named filter chipsfilterPresetsfilters, toolbar, state
autoRefreshautoRefresh()Silent reload on an intervalautoRefreshtoolbar, lifecycle
softDeletessoftDeletes()"Show deleted" togglesoftDeletesrequest, row, toolbar
actionsactions()Row buttons and ⋯ menuactionsrow
selectionselection()Checkboxes, select all, bulk barselectionrow
rowReorderrowReorder()Drag or keyboard-move rows, save in onEndrowReorderrow
keyboardGridkeyboardGrid()Arrow-key cell navigation, one tab stopkeyboardGridlifecycle
excelexcel().xlsx downloadexceltoolbar, export
csvcsv().csv downloadcsvtoolbar, export
printprint()Print view (and PDF)printtoolbar, export
footerfooter()Summary row in <tfoot>footerrender, export
metaBindmetaBind()Response fields → page elementsmetaBindrender
button.reloadbutton.reload()Reload buttonreloadButtontoolbar
button.resetStatebutton.resetState()Reset the saved viewresetStateButtontoolbar
button.custombutton.custom()Your own toolbar buttonits nametoolbar
button.groupbutton.group()Toolbar dropdownits nametoolbar

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.

SlotDefault contents (order)
startsearch box (0) · colVis (10) · button.reload (20) · button.resetState (30) · Export menu (40) · button.custom (50) · button.group (60)
endautoRefresh (−20) · softDeletes (−10) · record count (count: true, 0)
filtersfilterPresets (−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.

js
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(),
];
js
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")],
});
html
<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.

js
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: false does 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 can may be a function of the row: { id: "delete", can: (row) => row.status !== "done" }. See actions.
  • can is 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.

Released under the MIT License.