Defining grids (server)
Every grid is backed by a GridDefinition — the single source of truth for
which columns exist, how they map to SQL, which operations are allowed, and which
driver runs the queries. It is also the security boundary: only declared columns
are ever referenced in SQL, and all values are bound.
Creating a definition
use Elyra\DataGrid\Server\Grid;
$grid = Grid::table('sales') // table name
->connection('elyrasql') // a config/database.php connection (default: app default)
->driver('elyrasql') // 'elyrasql' (default) | 'mysql' | GridDriver instance
->key('id'); // primary key (stable pagination + editing/selection)
Declaring columns
Use ->columns([...]) for quick defaults, and ->column(...) for control:
$grid
->columns(['id', 'store_id', 'region', 'category', 'sku'])
->column('status',
editable: true,
editor: 'select',
rules: 'required|in:pending,paid,shipped,delivered,returned',
)
->column('qty', type: 'number', editable: true, rules: 'required|integer|min:0')
->column('revenue', type: 'number', editable: true, rules: 'required|numeric')
->column('margin', type: 'number')
->searchable(['sku', 'category']);
column() parameters
| Parameter | Type | Default | Purpose |
|---|---|---|---|
key |
string | — | Protocol field name (what clients send). |
column |
?string | = key |
Real SQL column. |
expression |
?string | null | Raw SQL expression (used instead of column, not quoted, not writable). |
sortable |
bool | true | Allow sorting. |
filterable |
bool | true | Allow filtering / facets. |
searchable |
bool | false | Include in global search. |
aggregatable |
?bool | numeric→true | Allow aggregate functions. |
type |
string | string |
string | number | date | bool (formatting/editor hint). |
editable |
bool | false | Write allow-list — only these can be mutated. |
editor |
string | text |
text | number | select | date | checkbox. |
rules |
string|array|null | null | Laravel validation rules applied on edit. |
options |
array | [] |
[['value'=>.., 'label'=>..]] for select editors. |
Computed columns
$grid->column('full_name', expression: "CONCAT(first_name, ' ', last_name)");
Expression columns are read-only (cannot be edited) and are emitted verbatim, so never interpolate user input into them.
Answering requests
use Elyra\DataGrid\Protocol\GridRequest;
$response = $grid->respond(GridRequest::fromArray($request->all()));
respond() returns a GridResponse array: rows,
view, and any opted-in total, groups, aggregates, facets, timing.
Drivers
| Driver | Facets | Rollup | Percentile | Hybrid search |
|---|---|---|---|---|
elyrasql (default) |
FACET() single pass |
✅ | ✅ | ✅ |
mysql (fallback) |
N × GROUP BY |
✅ | ✖ | ✖ |
Grid::table('sales')->driver('mysql'); // portability fallback
Grid::table('sales')->driver(new MyCustomDriver()); // implement Contracts\GridDriver
Security model
- Clients reference columns by name. Unknown fields are rejected
(
GridException), so a client can never query a column you did not declare. - Sorting/filtering honor per-column
sortable/filterableflags. - All filter/search values are passed as bound parameters.
- Editing only writes columns marked
editable; validationrulesrun first.
Mutations (editing) and export
The same definition powers editing and export:
use Elyra\DataGrid\Protocol\GridMutation;
$result = $grid->mutate(GridMutation::fromArray($request->all())); // create/update/delete
$response = $grid->export(GridRequest::fromArray($r->all()), 'csv'); // StreamedResponse
Full reference
See the Server API reference for every class and method.