DataGrid Architecture
Serenity grids are built from a layered stack. At the top is the DataGrid widget from @serenity-is/corelib, which orchestrates everything: it creates a SleekGrid instance for rendering, uses a RemoteView as its data source, builds columns from metadata, and wires up the toolbar, filters, pager, and persistence.
The Layers
| Layer | Type | Responsibility |
|---|---|---|
| Grid widget | DataGrid / EntityGrid (@serenity-is/corelib) |
Orchestrates columns, toolbar, filters, pager, persistence, and (for EntityGrid) CRUD dialogs and routing |
| Grid engine | SleekGrid (@serenity-is/sleekgrid) |
Renders the virtualized table: columns, rows, cell editors, formatters, selection, grouping |
| Data source | RemoteView (@serenity-is/corelib) |
Loads data from the server, handles sorting, paging, filtering, and grouping |
| Metadata | PropertyItem[] |
Column and form definitions generated server-side from your columns/form classes |
DataGrid
DataGrid<TItem, P> is the base grid widget. It extends Widget and implements IDataGrid and IReadOnly. It is responsible for:
- Creating the SleekGrid instance —
createSlickGrid()constructs anew SleekGrid(...)with the processed columns and options, and registers theAutoTooltipsplugin. - Building columns —
createColumns()convertsPropertyItemmetadata into SleekGridColumnobjects (viaPropertyItemColumnConverter), thenpostProcessColumns()applies edit links, formatters, and other column transforms. - Providing grid options —
getSlickOptions()returns theGridOptions(multi-select off, multi-column sort on, cell navigation off by default). - Wiring the toolbar —
getButtons()returns theToolButton[]shown in the grid's toolbar. - Wiring filters — the advanced filter bar (
FilterDisplayBar+FilterStore) and quick filters (QuickFilterBar). - Paging — the
SlickPagerwidget, driven by theRemoteView. - Persistence — saving/restoring column widths, visibility, sort, and filters (see Persisting Settings).
- Keyboard — a protected
onKeyDown(e, row, cell)is called for a key pressed in the grid before the grid handles it, so a grid class can handle a key by callingpreventDefault()andstopImmediatePropagation()on the event (e.g.EntityGridopens the dialog of the row on Enter in a grid with the row cursor). - Data loading —
prepareSubmit()/onViewSubmit()prepare the request parameters, and the view loads data from the server.
EntityGrid
EntityGrid<TItem, P> extends DataGrid and adds entity/CRUD integration:
- Service integration —
getService()returns the service base URL (e.g.LanguageService.baseUrl). - Dialog integration —
getDialogType()returns the dialog class used for add/edit. - Routing — handles hash routes like
#edit/123and#newto open dialogs. - Toolbar buttons — adds the standard add/edit/delete buttons and the include-deleted toggle.
- Quick search — adds the quick search input.
A typical generated grid (LanguagePage.ts) wires these up:
class LanguageGrid<P = {}> extends EntityGrid<LanguageRow, P> {
static override[Symbol.typeInfo] = this.registerClass(nsAdministration);
protected override getColumnsKey() { return LanguageColumns.columnsKey; }
protected override getDialogType() { return LanguageDialog; }
protected override getRowDefinition() { return LanguageRow; }
protected override getService() { return LanguageService.baseUrl; }
}
RemoteView
RemoteView<TItem> is the grid's data source. It implements IRemoteView (which extends SleekGrid's IDataView) and adds server-side data operations:
- Loading — calls the list service with the current request parameters.
- Sorting — sends the sort columns to the server.
- Paging — tracks the current page and page size.
- Filtering — applies quick filters and advanced filters to the request.
- Grouping — supports server-side grouping and group totals.
The grid's view property holds the RemoteView. You can access it to read the current items, page info, or to trigger a refresh.
A data view has a destroy() method that aborts its pending request and stops notifying, and DataGrid.destroy() calls it,
so rows that arrive after a grid is destroyed no longer reach listeners that may be gone. A custom view should implement it the
same way.
Grouping
Grouping is rendered by SleekGrid's GroupItemMetadataProvider, which the view registers:
- The provider gets the grid it is registered with, so a view can create it and still have it read the columns (e.g. to find
the group cell column), and it renders the rows again when the grid changes.
IDataView.setGroupItemMetadataProviderand the IGroupItemMetadataProvider interface let a view accept it. indentDataRows(on by default) indents the data rows under their group rows, throughslick-group-level-Nclasses and the--sg-group-indentvariable instead of inline styles, so it works under a content security policy (up to 8 levels).displayTotalsRowtakesboolean | "groupheader"and replaces thegroupRowTotalsoption: the totals of a group are shown on a row of their own, on the group row in its summary columns, or not at all, per grouping level. ThedisplayTotalsRowview option (also inDataGrid.defaultOptions) sets the default of the levels that don't set it. The group cell of a row whose totals are on the group row spans up to the first summary column, and the other cells of the group row keep the formatter of their own column.- Space toggles the group of the focused row, and the left and right arrows collapse and expand it at the first and last cell that can be focused, so a grouped grid can be navigated from the keyboard.
- A column with the
skipGroupCellflag (set on the selection columns) is left out of the group cell.
Breaking change:
GroupInfo.displayTotalsRowchanged its type toboolean | "groupheader"and replaced thegroupRowTotalsoption ofGroupItemMetadataProvider.
How a Grid Loads Data
- The grid calls
prepareSubmit(), which prepares the request parameters (sort, filters, paging) inview.params. getGridCanLoad()notifiesonCanSubmitsubscribers; if any cancel, loading stops.- The
RemoteViewcalls the list service (e.g.LanguageService.List). - The response (
ListResponse) populates the view's items and total count. - The view notifies the grid, which re-renders the visible rows.
See Also
- DataGrid (API reference) — the full
DataGridAPI. - EntityGrid (API reference) — the full
EntityGridAPI. - RemoteView (API reference), IRemoteView (API reference) — the data source.
- SleekGrid (API reference) — the grid engine.
- Creating and Configuring Grids — building grids step by step.
- EntityGrid CRUD — CRUD workflows with dialogs.
- Persisting Settings — saving grid settings.
- Frontend Framework Overview — the three client-side packages and how they fit together.