Skip to content

SSP wire: ssp() and yajra() ​

Endpoints written for DataTables' server-side processing (SSP) keep working unchanged: datagrids sends the parameter set DataTables 1.10 sends, encoded byte for byte like jQuery's $.param, and reads the same response. Two factories speak this wire:

ssp()yajra()
Forany SSP endpoint (PHP, .NET, Python, Node…)Laravel + yajra/laravel-datatables
Default methodGETPOST
Untyped cellstextHTML
Everything elseidenticalidentical

yajra() renders untyped cells as HTML because yajra escapes every value that is not in rawColumns on the server; rendering those as text would print &. Any other SSP server may send raw text, so ssp() keeps cells as text. Cells are text by default; HTML is an explicit opt-in everywhere else.

Change the status, sort, search or page, then read the Request and Response tabs. The Simulate buttons make the next response fail.

Simulate
js
import { Datagrid, column, serverSide, yajra, filterPanel, metaBind } from "@akinozgen17/datagrids";

const usd = new Intl.NumberFormat("en-US", { style: "currency", currency: "USD" });

new Datagrid("#proto-ssp", {
  label: "Agents (SSP wire)",
  columns: [
    column.index(),
    { key: "ref", title: "Ref" },
    { key: "name", title: "Name" },
    { key: "unit", title: "Unit", visible: false }, // hidden columns still travel in columns[]
    column.money("amount", { title: "Amount", currency: "USD", locale: "en-US" }),
    { key: "status_html", title: "Status", sortable: false, searchable: false }, // server HTML
  ],
  sort: [["amount", "desc"]],
  pageSize: 5,
  use: [
    serverSide({ url: "/api/agents", protocol: yajra(), csrf: true }),
    filterPanel({ fields: { status: "#proto-ssp-status" } }), // page filter → plain `status` parameter
    metaBind({ "#proto-ssp-sum": { value: "summary.total", format: (v) => usd.format(v) } }),
  ],
});
html
<div class="demo-form">
  <label>Status
    <select id="proto-ssp-status">
      <option value="">Any status</option>
      <option value="open">Open</option>
      <option value="pending">Pending</option>
      <option value="done">Done</option>
      <option value="cancelled">Cancelled</option>
      <option value="draft">Draft</option>
    </select>
  </label>
</div>
<div class="demo-kpis">
  <div class="demo-kpi"><span>summary.total (extra response key)</span><strong id="proto-ssp-sum">—</strong></div>
</div>
<table id="proto-ssp"></table>

Options ​

js
serverSide({ url: "/agents/data", protocol: yajra({ allowAll: true }) })
OptionTypeDefaultDescription
dataobject | (d) => unknownnoneDataTables ajax.data: an object is deep-merged into the parameters; a function may mutate d or return a replacement (an object, or a ready-made string)
dataSrcstring | (json) => rowsdata, then aaDataDataTables ajax.dataSrc: a dotted path to the rows ("" = the body is the array) or a function
method"GET" | "POST"ssp: GET, yajra: POSTserverSide({ method }) overrides it too
cells"text" | "html"ssp: text, yajra: htmlRender mode of untyped columns
allowAllbooleanfalseLets a -1 page size ("All") reach the server as length=-1

Extra parameters belong in serverSide({ params }) or a filter panel; keep data for porting an existing ajax.data function.

Request ​

Transport ​

yajra() / POSTssp() / GET
Whereform bodyquery string, plus _=<timestamp> (jQuery's cache: false)
Content-Typeapplication/x-www-form-urlencoded; charset=UTF-8none
Acceptapplication/json, text/javascript, */*; q=0.01same
X-Requested-WithXMLHttpRequestsame
CSRF (csrf: true)X-CSRF-TOKEN header and a _token fieldX-CSRF-TOKEN header

A _token already present in the parameters is left alone. No JSON body is ever sent.

Parameters ​

Every request carries the full set, in this order, whatever the user did:

text
draw=1
columns[0][data]=
columns[0][name]=
columns[0][searchable]=false
columns[0][orderable]=false
columns[0][search][value]=
columns[0][search][regex]=false
columns[1][data]=name
columns[1][name]=
columns[1][searchable]=true
columns[1][orderable]=true
columns[1][search][value]=
columns[1][search][regex]=false
…
order[0][column]=3
order[0][dir]=desc
start=10
length=10
search[value]=leon kennedy
search[regex]=false
unit=R.P.D.
_token=…
ParameterValue
drawCounter starting at 1, incremented per request of this protocol instance. Sent, never trusted
columns[i][data]The column's data path, else its key. Empty for the index, select and actions columns
columns[i][name]The column's name option, else empty
columns[i][searchable]true/false from the column (searchable, default true for data columns)
columns[i][orderable]true/false from the column's sortable
columns[i][search][value], [regex]A plain grid.filters({ key: value }) on a searchable column: an anchored, escaped regex for equality (^R\.P\.D\.$, regex: true); an array becomes ^a$|^b$. A filter on a non-searchable column is not sent (dev notice). Otherwise empty / false (typed column filters use columnControl, below; between and notIn are not offered on this protocol)
order[i][column], order[i][dir]Index into columns[] and asc/desc, one entry per sort key
start(page - 1) × pageSize
lengthPage size, or -1 (see below)
search[value], search[regex]The global search text; regex is always false
page filters, _tokenPlain top-level parameters, after the protocol's own

Rules:

  1. columns[] is in definition order and includes hidden columns. Hiding a column (visible: false, the column menu) or reordering columns on screen never changes the indexes the server sees. A column with can: false does not exist at all: it is not sent.
  2. Default order. While no sort is active the grid sends order[0][column]=0&order[0][dir]=asc, like DataTables' default order: [[0, 'asc']]. That includes clearing the sort at runtime (a header click, grid.sort([]), a state reset, ?sort=), even when a sort option was given. Only an explicit sort: [] option sends no order parameters (the server's own order). Once the user sorts, the chosen key is sent.
  3. length=-1 is sent when paging is off (paging: false), or when the user picks "All" (-1 in pageSizes) and the protocol has allowAll: true. Without allowAll, "All" is clamped to maxPageSize (1000 by default) with the DG013 warning.
  4. Page filters are plain parameters. Values from serverSide({ params }), filterPanel(), softDeletes() (_deleted=1), lazyColumns() (lazy[]=key for each visible lazy column) and grid.filters() keys that are not column keys are appended as name=value (arrays as name[]=a&name[]=b). Your controller reads them like any request input.
  5. data (the ajax.data port) runs last, after page filters, so it can still change start, length or search.
  6. DataTables 2.x and 3.x additionally send order[i][name]. datagrids sends the 1.10 set; a server that reads order[i][name] should fall back to columns[order[i][column]][name].

Encoding ​

The body (or query string) is identical to jQuery 3's $.param output:

ValueEncoded as
true / falsek=true / k=false
null, undefinedk=
[], {} (empty)nothing: the key is omitted
["a", "b"]k[]=a&k[]=b
[{ x: 1 }]k[0][x]=1
{ a: { b: 1 } }k[a][b]=1
a functioncalled; its result is encoded
charactersencodeURIComponent; in POST bodies %20 becomes +

Typed column filters (columnControl) ​

A typed filter on a column (grid.filters({ amount: { op: "gte", value: 100 } }) or the columnFilters() header UI) travels in that column's entry, in the DataTables ColumnControl format that yajra/laravel-datatables 12.7+ reads:

text
columns[3][columnControl][search][value]=100
columns[3][columnControl][search][logic]=greaterOrEqual
columns[3][columnControl][search][type]=num
opSent as
eq, nelogic=equal, notEqual
gt, gte, lt, ltelogic=greater, greaterOrEqual, less, lessOrEqual
contains, notContains, starts, endssame names
empty, notEmptysame names, empty value
incolumns[i][columnControl][list][]=a&…[list][]=b
between, notInnot sent: ColumnControl has no equivalent

type is num for number and money columns, date for date columns, text otherwise. Filters on columns with searchable: false are never sent (yajra would apply them anyway). Older yajra versions ignore columnControl; filter with page parameters there.

Response ​

json
{
  "draw": 1,
  "recordsTotal": 1000,
  "recordsFiltered": 941,
  "data": [
    { "DT_RowId": "row_1993", "id": 1993, "name": "Ada Wong", "amount": 3121.74, "status_html": "<span class=\"dg-chip\" data-tone=\"bad\">Cancelled</span>" }
  ],
  "summary": { "total": 7617927.4 }
}
MemberRead as
data (or aaData, or dataSrc)The rows. Anything that is not an array becomes an empty page
recordsTotal / recordsFiltered (or iTotalRecords / iTotalDisplayRecords)Parsed as base-10 integers, so numeric strings work. Missing: the row count is used, and recordsFiltered falls back to recordsTotal
drawIgnored (see sequencing)
error (or sError)A string or true: the rows still render and a non-blocking error banner appears (see Errors)
DT_RowIdThe <tr> id, and the row key when the row has no id
DT_RowClassClasses added to the <tr>
DT_RowData, DT_RowAttrNot applied. Use the grid's rowAttrs(row) option
queries, inputDeleted before anything else sees the body (Laravel debug output)
any other top-level keyKept: result.meta in the response event, the raw body in grid.lastResponse(), and bindable with metaBind() (summary.total in the demo)

Cells ​

Columnssp()yajra()
Untyped ({ key: "name" })textHTML
column.text()texttext: escaped values show as &amp;, so prefer untyped columns for strings
column.html()HTMLHTML
column.number(), money(), date(), badge(), link()rendered from the valuerendered from the value
render returning a stringtext, unless the column is column.html()same

Sequencing ​

draw can arrive as a string, be missing or come back stale from a cache. datagrids doesn't depend on it: every new request aborts the one in flight, and a response is used only if it belongs to the latest request. A slow, stale or draw-less response can't freeze the grid in "Processing…".

Errors ​

Every failure, on any protocol, becomes one DatagridError { kind, status, message, detail?, retryable }. The grid fires the error event, then shows the message: as a banner above the rows when rows are already on screen, otherwise in place of the body. Server text (which may contain SQL) goes only into detail: the console (DG012) and a collapsed "Details" field while warnings are on.

ResponsekindMessage shownRetry
200 with error / sError (string or true)server"The server returned an error (200)." (rows still render)yes
200 with status: "error" and a messageserverthat messageyes
200 whose body is not JSONparse"The server response could not be read."no
redirect to a non-JSON page whose URL looks like a login pagesession"Your session has expired. Please sign in again."no
redirect to any other non-JSON pageforbidden"You are not allowed to view this list."no
401, 419session"Your session has expired. Please sign in again."no
403forbiddenthe body's message, else "You are not allowed to view this list."no
410protocolthe body's message, else the generic textno
422validationthe body's message (Laravel's message, else the first errors entry)no
429httpthe body's message, else the generic textyes
other 4xxhttp"The server returned an error (404)."no
5xxhttp"The server returned an error (500)."yes
network failurenetwork"The server could not be reached. Check your connection."yes
no answer within timeout (30 s)timeout"The server took too long to respond."yes
aborted by a newer requestabortnothing: silently dropped—

session errors also fire sessionexpired and call configure({ onSessionExpired }) when set. The messages come from the grid's messages (English or Turkish, overridable). Per grid, errorMode: "silent" keeps the grid quiet (events still fire) and errorMode: "throw" rethrows. Nothing ever calls alert().

Compatibility tests ​

The rules on this page are pinned by unit tests in tests/unit/server.test.ts. The encoder is compared byte for byte with the real jQuery $.param on a corpus of inputs.

RuleTest
Encoding equals jQuery $.param; + for spaces in POST bodiescase N, "form body turns %20 into + like jQuery.ajax"
Full parameter set, DataTables order, hidden columns included"sends the full parameter set in DataTables order, hidden columns included"
Default order while no sort is active; only an explicit sort: [] sends none"default order [[0,'asc']] only when no sort was configured; order:[] sends nothing", "clearing at runtime keeps the default order on the wire; only an explicit sort:[] drops it"
length=-1 when paging is off"paging off → length -1"
data: mutate, replace, deep merge"ajax.data: mutate, return replacement, static deep merge"
POST form body and Accept; GET cache buster"POST form body + jQuery Accept; GET adds _= cache buster"
Numeric strings, ignored draw, extra keys"decode: numbers normalized, draw ignored, extras in meta"
dataSrc"dataSrc string/function"
columnControl and page filters"typed column filters become columnControl, page filters plain params"
Error table"500 JSON: generic message, server text only in detail", "419 / 401 → session", "302 to HTML → forbidden (login → session)", "422 Laravel and RFC 9457", "403 / 410 / 429", "200 + error / status:error", "network / timeout"

Server checklist ​

  • Read every parameter defensively; datagrids always sends the full set, other clients may not.
  • Map order[i][column] through columns[i][data]/[name] and whitelist the result before it reaches SQL.
  • Cap length (and decide whether -1 is allowed).
  • Answer expired sessions with 401/419 JSON and missing permissions with 403 JSON, not with a redirect to an HTML page.
  • Keep APP_DEBUG-style output (queries, input, exception text in error) off in production; datagrids hides it from users, but it still crosses the network.

Released under the MIT License.