datagrids protocol v1
The datagrids protocol (dgp) is a small JSON protocol between a list UI and a server: the client asks for one page of rows with a sort, a search text and typed filters; the server answers with the rows, paging facts, optional counts and aggregates. It is what dgp() speaks.
| Property | Value |
|---|---|
| Spec version | 1.0 (2026-10-27) |
| Status | Stable. Changes within v1 are additions only |
| JSON Schema (draft 2020-12) | request.schema.json · response.schema.json · error.schema.json |
| Client | serverSide({ url, protocol: dgp() }) |
Try it: change the sort, search, open a column filter (the funnel icon in a header), switch the count mode, simulate an error, and read the Request and Response tabs.
import { Datagrid, column, serverSide, dgp, columnFilters, metaBind } from "@akinozgen17/datagrids";
import { statusLabels, statusTones } from "./data.js";
const usd = new Intl.NumberFormat("en-US", { style: "currency", currency: "USD" });
new Datagrid("#proto-dgp", {
label: "Agents (datagrids protocol v1)",
columns: [
column.text("name", { title: "Name" }),
column.text("unit", { title: "Unit" }),
column.badge("status", { title: "Status", labels: statusLabels, tones: statusTones }),
column.money("amount", { title: "Amount", currency: "USD", locale: "en-US" }),
column.date("date", { title: "Date" }),
],
sort: [["amount", "desc"]],
pageSize: 5,
use: [
serverSide({ url: "/api/dgp/agents", protocol: dgp({ count: "exact" }), csrf: true }),
columnFilters(), // typed filters → filters: { key: { op, value } }
metaBind({ "#proto-dgp-sum": { value: "meta.aggregates.amount.sum", format: (v) => usd.format(v) } }),
],
});<div class="demo-kpis">
<div class="demo-kpi"><span>Amount (all matching rows)</span><strong id="proto-dgp-sum">—</strong></div>
</div>
<table id="proto-dgp"></table>1. Overview and versioning
The key words MUST, MUST NOT, REQUIRED, SHOULD, SHOULD NOT, RECOMMENDED, MAY and OPTIONAL are to be interpreted as described in RFC 2119 and RFC 8174 when, and only when, they appear in all capitals.
Terms:
- Client: the code that builds requests and renders rows (for example a datagrids grid).
- Server: the endpoint that answers them.
- Field: a named value of a row (
name,amount). Sort keys, filter keys andfieldsentries are field keys. - Schema: the server's own list of fields it exposes, with their types and which of them are sortable, searchable and filterable. The schema lives on the server; the protocol never sends column definitions, SQL expressions or indexes.
Versioning:
- Every request body MUST contain
"v": 1. Every successful response body MUST contain"v": 1. - A server that receives a
vit does not support MUST answer400withcode: "unsupported_version". - The spec version is independent of the datagrids library version. A library release states which protocol versions it speaks; this one speaks v1.
- Within v1 the spec only grows: new OPTIONAL members, new error codes, new warning codes. A change that would make a conforming v1 peer fail is a new major version (
"v": 2, a new/protocol/v2/page). - Both sides MUST ignore members they do not know, in every object. The JSON Schemas allow additional properties for this reason.
2. Transport
2.1 POST JSON (default)
- The client sends
POST <endpoint>withContent-Type: application/jsonand a request body. - The client SHOULD send
Accept: application/json, application/problem+json. - A successful answer is
200withContent-Type: application/jsonand a response body. - An error is a 4xx/5xx status with
Content-Type: application/problem+jsonand an error body. - When the endpoint authenticates with cookies, the server SHOULD require a CSRF token header (
X-CSRF-TOKENin Laravel). The reference client sends it withcsrf: true, together withX-Requested-With: XMLHttpRequest.
2.2 GET form (optional)
A server MAY also accept the same request as query parameters (dgp({ method: "GET" })), which makes responses cacheable and links shareable. The mapping is flat:
| Request member | Query parameter | Example |
|---|---|---|
page.size, page.number | page[size], page[number] | page[size]=25&page[number]=2 |
sort | sort: comma list, - prefix = descending | sort=-amount,name |
q | q | q=kennedy |
fields | fields: comma list | fields=name,unit,amount |
count | count | count=none |
filters.<key> | filter[<key>][<op>]=<value>; list values comma-joined | filter[status][in]=open,pending |
params.<name> | <name> (top level) | _deleted=1 |
- Parameters are form-encoded (brackets and commas percent-encoded on the wire).
vandrequestIdare not sent in the GET form; the endpoint path implies v1. - All values arrive as strings. The server coerces them by the field's type in its schema.
- List values MUST NOT contain commas in the GET form. A client that needs them MUST use POST.
emptyandnotEmptycarry an empty value:filter[deleted_at][empty]=.
3. Request
{
"v": 1,
"page": { "size": 25, "number": 1 },
"sort": [{ "key": "amount", "dir": "desc" }],
"q": "kennedy",
"filters": { "status": { "op": "in", "value": ["open", "pending"] } },
"fields": ["name", "unit", "status", "amount", "date"],
"count": "exact",
"requestId": "r-12",
"params": { "_deleted": 1 }
}| Member | Type | Required | Meaning |
|---|---|---|---|
v | 1 | REQUIRED | Protocol major version |
page | { size, number } | REQUIRED | size: integer ≥ 1. number: 1-based integer ≥ 1 |
sort | [{ key, dir }] | OPTIONAL | Sort keys in priority order; dir is asc or desc. Missing or empty: the server's default order. See Sorting |
q | string | OPTIONAL | Global search text. The client omits it when empty |
filters | { <key>: { op, value } } | OPTIONAL | Typed filters, combined with AND. See Filtering |
fields | string[] | OPTIONAL | The fields the client renders. Missing: the server's default field set |
count | exact | estimate | none | OPTIONAL | Counting the client asks for; missing means exact. See Counting |
requestId | string | OPTIONAL | Correlation id for logs. The server MAY echo it |
params | object | OPTIONAL | Page-specific parameters that are not typed filters. Their meaning is server-defined |
Rules:
- Servers MUST accept a request in which every OPTIONAL member is missing.
- Servers MUST enforce a maximum page size. When
page.sizeexceeds it, the server MUST either answer422withcode: "page_size_exceeded", or clamp the size, report the size it used in the response'spage.sizeand add apage_size_clampedwarning. A maximum of 1000 matches the reference client's defaultmaxPageSize. fieldsentries the server does not know SHOULD be ignored (and MAY be reported as a warning).fieldsnever widens what the server exposes: see Response rule 3.- A
page.numberpast the last page is not an error: the server answers200with an emptyrowsarray andhasMore: false.
What the reference client puts where:
| Grid input | Request member |
|---|---|
grid.page(), grid.pageSize() | page.number, page.size |
sort option, header clicks, grid.sort() | sort (column keys) |
The search box, grid.search() | q |
grid.filters({ status: "open" }) | filters.status = { op: "eq", value: "open" } |
grid.filters({ unit: ["R.P.D.", "U.B.C.S."] }) | filters.unit = { op: "in", value: [...] } |
grid.filters({ amount: { op: "gte", value: 100 } }), columnFilters() | filters.amount as given |
| Columns (except index, select and actions columns) | fields: each column's data path, else its key |
dgp({ count }) | count (default exact) |
serverSide({ params }), filterPanel(), softDeletes(), lazyColumns() | params (e.g. params._deleted, params.lazy) |
csrf: true | X-CSRF-TOKEN header, and _token in params |
Function filters (grid.filters({ key: (value, row) => … })) are client-only and never sent. Filters set to null, "" or [] are removed and never sent.
3.1 Export requests (informative)
An export of "all matching rows" (grid.exportRows("all"), excel({ scope: "all" })) sends the same request with page: { size: <maxPageSize>, number: 1 } (1000 by default). Servers SHOULD allow that size. Larger exports belong to a separate endpoint: the page posts grid.query() there and the server runs the same query in a job.
4. Response
{
"v": 1,
"rows": [
{ "id": "1737", "name": "Cindy Lennox", "status": "pending", "amount": 19991.51 }
],
"page": { "size": 25, "number": 1, "hasMore": true },
"count": { "mode": "exact", "total": 1000, "filtered": 375 },
"meta": {
"aggregates": { "amount": { "sum": 3094860.95 } },
"facets": {},
"warnings": []
}
}| Member | Type | Required | Meaning |
|---|---|---|---|
v | 1 | REQUIRED | Protocol major version |
rows | object[] | REQUIRED | The page, in the requested order. May be empty |
page | { size, number, hasMore } | REQUIRED | The page actually returned. hasMore is true when a next page exists |
count | { mode, total?, filtered? } | REQUIRED | See Counting |
meta | { aggregates?, facets?, warnings? } | OPTIONAL | Side data, see below |
requestId | string | OPTIONAL | Echo of the request's requestId |
Rules:
- Every row MUST have an
id(string or integer) that is unique within the result and stable across requests. Clients compare ids as strings. Selection, row actions and row refreshes depend on it. - Values are typed data, not presentation: numbers as JSON numbers (or decimal strings such as
"1234.50"when precision matters), dates and times as ISO 8601 strings with an offset ("2026-09-01T10:00:00+03:00"), booleans astrue/false, missing values asnull. Servers SHOULD NOT send HTML. Clients render cells as text unless a column opts in to HTML. - A row MUST NOT contain fields outside the server's schema. A server SHOULD return exactly the requested
fieldsit knows, plusid. Never serialize whole models: what is not in the schema never leaves the server. meta.aggregatesholds raw numbers over every filtered row (not just the page), by field key and function:{ "amount": { "sum": 3094860.95, "avg": 8252.96 } }. Well-known functions:sum,avg,min,max,count.meta.facetsholds filter options by field key:{ "unit": [{ "value": "rpd", "label": "R.P.D.", "count": 12 }] }.meta.warningsholds non-fatal notes as{ code, message? }objects, e.g.{ "code": "page_size_clamped", "message": "Page size limited to 500." }.
The reference client exposes the whole body as grid.lastResponse() and in the response event (result.meta carries meta plus countMode), so metaBind() can write meta.aggregates.amount.sum into the page, as the demo above does.
5. Errors
Every error is a RFC 9457 problem details object, sent with the matching HTTP status and Content-Type: application/problem+json.
{
"type": "about:blank",
"title": "Invalid filter",
"status": 422,
"code": "validation_failed",
"retryable": false,
"errors": { "filters.date": ["The date range is invalid."] }
}| Member | Type | Required | Meaning |
|---|---|---|---|
type | URI reference | OPTIONAL | Problem type; about:blank when omitted |
title | string | REQUIRED | Short summary, safe to show to end users |
status | integer | REQUIRED | Same as the HTTP status |
detail | string | OPTIONAL | Occurrence-specific diagnostics. Clients MUST NOT show it to end users |
instance | URI reference | OPTIONAL | Identifies this occurrence (e.g. a log reference) |
code | string | REQUIRED | Machine-readable, snake_case (extension member) |
retryable | boolean | RECOMMENDED | Whether repeating the same request may succeed (extension member) |
errors | { <path>: string[] } | OPTIONAL | Validation messages by request path: filters.date, sort.0.key, page.size (extension member) |
Server rules:
- Use the right status. Never answer an API request with a
302redirect to an HTML login or "forbidden" page: answer401(or419for an expired CSRF session) or403with a problem body. - Never put stack traces, SQL or personal data in
title. Prefer to keep them out ofdetailtoo. - Validation failures (unknown sort key, unsupported operator, malformed value, page too large) are
422witherrorskeyed by request path.
Recommended codes:
| Status | code | retryable |
|---|---|---|
| 400 | invalid_request, unsupported_version | false |
| 401 / 419 | session_expired | false |
| 403 | forbidden | false |
| 422 | validation_failed, unknown_sort_key, unknown_filter, unsupported_filter, page_size_exceeded | false |
| 429 | rate_limited (with Retry-After) | true |
| 500 | server_error | true |
| 503 | unavailable | true |
How the reference client handles them (the same normalization applies to every protocol, see SSP → Errors):
| Response | Error kind | Shown message | Retry button |
|---|---|---|---|
401, 419 | session (+ sessionexpired event) | "Your session has expired…" | no |
302 to a non-JSON page | session if the URL looks like a login page, else forbidden | session / "You are not allowed…" | no |
403 | forbidden | problem message, else "You are not allowed…" | no |
422 | validation | problem message | no |
410 | protocol | problem message | no |
429 | http | problem message | yes |
| other 4xx | http | "The server returned an error (404)." | no |
| 5xx | http | "The server returned an error (500)." (server text only in error.detail) | yes |
200 with a body that is not JSON | parse | "The server response could not be read." | no |
| network failure, timeout | network, timeout | connection / timeout text | yes |
"Problem message" is title when the problem also has a detail, otherwise the first message in errors, otherwise the generic text. The reference client decides retries from the status; it does not read retryable or code yet. If the grid already shows rows, the error appears as a banner above them; otherwise it replaces the body.
6. Counting
Counting a filtered result can cost more than fetching the page. The client says what it needs; the server says what it did.
count.mode | total | filtered | Meaning |
|---|---|---|---|
exact | OPTIONAL | REQUIRED | Exact numbers. filtered: rows matching q and filters. total: rows before them |
estimate | OPTIONAL | REQUIRED | Approximations (e.g. from the query planner) |
none | absent | absent | Not counted |
- The server MAY answer with a cheaper mode than requested (
exact→estimate→none), never a more expensive one it was not asked for.count.modeMUST state what was done. - Clients MUST read
count.modefrom the response, not assume the requested one. page.hasMoreMUST be accurate in every mode. Without counts it is the only paging signal. Servers usually fetchsize + 1rows to know it.totalandfilteredare integers ≥ 0. Omittotalwhen it costs an extra query you don't want.
How the reference client shows each mode:
| Mode | Info text | Pager |
|---|---|---|
exact | "1–25 / 375 records (total 1,000)" | page field "of N", Last enabled |
estimate | same as exact (numbers are not marked as approximate yet) | same as exact |
none | "1–25 shown · total unknown" | Next while hasMore, Last disabled |
Switch count: none in the demo above to see the third row.
7. Sorting
sortis an ordered list; the first entry has the highest priority.keyis a field key from the server's schema, never a column index or an SQL expression.- The server MUST reject keys that are unknown or not sortable with
422(code: "unknown_sort_key",errors["sort.<i>.key"]). Never splice a key into SQL unchecked. - The server MUST produce a deterministic order and SHOULD append a unique tiebreaker (usually
id) so rows don't move between pages. - A missing or empty
sortmeans the server's default order (which also MUST be deterministic). - Where nulls sort is server-defined but MUST be consistent.
The reference client sends one key when a user clicks a header; a sort option with several entries (sort: [["unit", "asc"], ["amount", "desc"]]) sends them all.
8. Filtering
filters maps a field key to one filter object { op, value }. All filters MUST match (AND); v1 has no OR groups and no nesting. in and notIn express "any of" within one field. q and filters combine with AND.
op | value | Matches rows whose field… |
|---|---|---|
eq | scalar | equals the value |
ne | scalar | does not equal the value (empty fields match) |
gt / gte | number or date string | is greater than / at least the value |
lt / lte | number or date string | is less than / at most the value |
between | [min, max] | lies in the closed range min ≤ field ≤ max |
in | non-empty array of scalars | equals any of the values |
notIn | non-empty array of scalars | equals none of the values (empty fields match) |
contains | string | contains the text |
notContains | string | does not contain the text (empty fields match) |
starts | string | starts with the text |
ends | string | ends with the text |
empty | none | is null or "" |
notEmpty | none | is neither null nor "" |
Rules:
- Scalars are strings, numbers or booleans. Dates are ISO 8601 strings: a date (
2026-09-01) or a date-time with an offset. - Text operators (
contains,notContains,starts,ends) SHOULD be case-insensitive and SHOULD ignore diacritics, soisikfindsIşık.eqcompares exactly after coercion to the field's type. - Negative operators (
ne,notIn,notContains) MUST include rows whose field is empty. In SQL that means addingOR field IS NULL. - Comparison operators (
gt,gte,lt,lte,between) never match an empty field. - A date-only value compared with a date-time field SHOULD cover the whole day in the server's business time zone:
eq 2026-09-01matches that day,between ["2026-09-01", "2026-09-30"]includes all of September 30. emptyandnotEmptytake no value; servers MUST ignore one if present.- The server MUST validate every filter against its schema: an unknown key is
422withcode: "unknown_filter", an operator the field doesn't support or a malformed value is422withcode: "unsupported_filter"or"validation_failed", witherrors["filters.<key>"]. qis matched against server-chosen fields. It SHOULD follow rule 2 and MAY require a minimum length.
columnFilters() offers these operators per column type: text columns contains, notContains, starts, ends, eq, ne, empty, notEmpty; number and money columns eq, ne, gt, gte, lt, lte, between, empty, notEmpty; dates eq, gt, lt, between, empty, notEmpty; badges in, notIn.
9. Conformance
A conforming client:
- [ ] sends
v: 1and apagewithsize ≥ 1and a 1-basednumber; - [ ] sorts by field key and filters with the operators of §8 only;
- [ ] omits empty filters and never sends client-only predicates;
- [ ] ignores unknown members in responses and errors;
- [ ] reads
count.modeandpage.hasMorefrom the response and pages without counts when needed; - [ ] matches each response to the latest request it sent (abort or sequence numbers), not to
requestId; - [ ] renders values as text unless a column explicitly opts in to HTML;
- [ ] shows
title/errorsmessages to users and keepsdetailfor developers; - [ ] sends a CSRF header when the endpoint authenticates with cookies.
A conforming server:
- [ ] accepts
POSTwith a JSON body (the GET form is optional); - [ ] answers
400 unsupported_versionfor anyvother than1; - [ ] ignores unknown request members and accepts requests without the OPTIONAL ones;
- [ ] whitelists sort keys, filter keys, operators and fields against its schema (
422otherwise); - [ ] enforces a maximum page size (
422or clamp + warning); - [ ] returns a stable, unique
idon every row and no field outside its schema; - [ ] orders deterministically, with a unique tiebreaker;
- [ ] returns accurate
page.hasMoreand statescount.modetruthfully; - [ ] answers past-the-end pages with
200and emptyrows; - [ ] reports errors as
application/problem+jsonwith the right status, never as a redirect to HTML; - [ ] keeps SQL, stack traces and personal data out of
title.
10. Examples
The examples below come from the in-page demo server that also backs the demo at the top. Rows are shortened where marked. Each body validates against the JSON Schemas.
10.1 First page, exact count
Request:
POST /api/dgp/agents HTTP/1.1
Content-Type: application/json
Accept: application/json, application/problem+json
X-Requested-With: XMLHttpRequest{
"v": 1,
"page": { "size": 3, "number": 1 },
"sort": [{ "key": "amount", "dir": "desc" }],
"filters": { "status": { "op": "in", "value": ["open", "pending"] } },
"fields": ["name", "unit", "status", "amount", "date"],
"count": "exact",
"requestId": "r-1"
}Response (200, application/json):
{
"v": 1,
"rows": [
{ "id": "1737", "name": "Cindy Lennox", "unit": "U.B.C.S.", "status": "pending", "amount": 19991.51, "date": "2026-06-16T21:40:00.000Z" },
{ "id": "1911", "name": "Sheva Alomar", "unit": "S.T.A.R.S. Bravo", "status": "pending", "amount": 19849.61, "date": "2026-08-02T02:40:00.000Z" },
{ "id": "1342", "name": "Ethan Winters", "unit": "S.T.A.R.S. Bravo", "status": "open", "amount": 19753.5, "date": "2025-10-07T13:40:00.000Z" }
],
"page": { "size": 3, "number": 1, "hasMore": true },
"count": { "mode": "exact", "total": 1000, "filtered": 375 },
"meta": { "aggregates": { "amount": { "sum": 3094860.95 } }, "facets": {}, "warnings": [] }
}10.2 Search, range filter, no count
Request:
{
"v": 1,
"page": { "size": 2, "number": 4 },
"sort": [{ "key": "date", "dir": "desc" }],
"q": "kennedy",
"filters": { "amount": { "op": "between", "value": [1000, 20000] } },
"fields": ["name", "amount", "date"],
"count": "none",
"requestId": "r-7"
}Response:
{
"v": 1,
"rows": [
{ "id": "1686", "name": "Leon S. Kennedy", "amount": 17456.45, "date": "2026-06-30T15:40:00.000Z" },
{ "id": "1878", "name": "Leon S. Kennedy", "amount": 6111.1, "date": "2026-06-26T09:40:00.000Z" }
],
"page": { "size": 2, "number": 4, "hasMore": true },
"count": { "mode": "none" },
"meta": { "aggregates": { "amount": { "sum": 422607.33 } }, "facets": {}, "warnings": [] }
}10.3 The same as 10.1, GET form
GET /api/dgp/agents?page%5Bsize%5D=3&page%5Bnumber%5D=1&sort=-amount&fields=name%2Cunit%2Cstatus%2Camount%2Cdate&count=exact&filter%5Bstatus%5D%5Bin%5D=open%2Cpending HTTP/1.1
Accept: application/json, application/problem+jsonDecoded: page[size]=3 & page[number]=1 & sort=-amount & fields=name,unit,status,amount,date & count=exact & filter[status][in]=open,pending. The response is the same as in 10.1.
10.4 Validation error
HTTP/1.1 422 Unprocessable Content
Content-Type: application/problem+json{
"type": "about:blank",
"title": "Invalid filter",
"status": 422,
"code": "validation_failed",
"retryable": false,
"errors": { "filters.date": ["The date range is invalid."] }
}The grid shows "The date range is invalid." without a Retry button.
10.5 Server error
HTTP/1.1 500 Internal Server Error
Content-Type: application/problem+json{
"type": "about:blank",
"title": "Server error",
"status": 500,
"detail": "SQLSTATE[42S22]: Column not found: 'unitt'",
"code": "server_error",
"retryable": true
}The grid shows "The server returned an error (500)." with Retry. The detail text reaches only the developer console (and a collapsed "Details" field while warnings are on), which is why it must never be needed by end users.
11. Changelog
| Version | Date | Changes |
|---|---|---|
| 1.0 | 2026-10-27 | First release: request, response, errors (RFC 9457), counting, sorting, 15 filter operators, GET form, JSON Schemas |
Related
- Server protocols overview: when to choose dgp over the SSP wire or Laravel's paginator.
- Data sources and Server protocols guide: attaching
serverSide({ protocol: dgp() }). - columnFilters: the header filter UI that produces typed filters.
- States and errors: how errors look in the grid.