Caelrik\Ui\Data
Aggregate
final class Caelrik\Ui\Data\Aggregate
Column totals: the functions a Grid column can total with, how rows of a PHP array are totalled, and how a total is written. resources/js/grid-summary.js does the same in the browser, so both write a total alike.
Constants
| Constant | Value |
|---|---|
SUM | 'sum' |
AVG | 'avg' |
COUNT | 'count' |
MIN | 'min' |
MAX | 'max' |
FUNCTIONS | ['sum', 'avg', 'count', 'min', 'max'] |
Methods
assertFunction
static assertFunction(string $function): voidcompute
static compute(string $function, iterable $values): int|float|nullTotals values as SQL does: empty values (null, '') are left out, count counts the others, and the other functions only read numbers. With no number, only sum and count give 0.
groupKey
static groupKey(mixed $value): stringMatches a group's value as a database and PHP may give it: 3 and '3', true and 1, a date and its text are the same group. resources/js/grid-summary.js has the same key.
number
static number(mixed $value): int|float|nullA number from PHP or a database ('1250.50', 3, true): int when it has no fraction.
format
static format(int|float|null $value, string $function, ?int $decimals = null, string $decimal = '.', string $thousands = ','): stringWrites a total with its separators. Without $decimals: none for a count or a whole number, 2 otherwise.
ArrayDataSource
final class Caelrik\Ui\Data\ArrayDataSource implements DataSourceInterface
In-memory data source for plain PHP arrays (framework-free apps, fixtures, tests).
Methods
__construct
__construct(array $rows)fetch
fetch(DataRequest $request): DataResultArrayEventSource
final class Caelrik\Ui\Data\ArrayEventSource implements EventSourceInterface
In-memory event source for plain PHP arrays, fixtures and tests.
Methods
__construct
__construct(iterable $events)between
between(DateRange $range): iterableCardMove
final class Caelrik\Ui\Data\CardMove
A checked move of a task board's card (TaskBoard::cardMove()): the column it goes to, and its position there, from 0 at the top; null puts it last (a move sent without JavaScript).
Methods
__construct
__construct(string $column, ?int $position)CellEdit
final class Caelrik\Ui\Data\CellEdit
A checked change to one grid cell (Grid::cellEdit()): the column's field and its new value, typed as its editor reads it.
Methods
__construct
__construct(string $field, string|int|float|bool|null $value)answer
answer(mixed $saved = null, ?string $message = null): arrayThe answer the grid reads after a save: {"value": ...}. Pass the value as saved when the application changed it (rounded, normalised), and a message to show in a toast.
DataRequest
final class Caelrik\Ui\Data\DataRequest
Normalized paging, sorting, search and filter parameters.
Built from query parameters in either of two formats:
- DataTables server-side protocol: draw, start, length, order[i][column|dir], columns[i][data], search[value]
- Caelrik simple format: page, per_page, sort=name,-created_at, search, filter[field]=value
Typed filters (a Grid's column filters) are read from filter[field] in both formats: filter[name]=ada (text), filter[status]=active (exact), filter[verified]=1 (boolean), filter[created_at][from]=2026-01-01&filter[created_at][to]=2026-01-31 (date range).
Constants
| Constant | Value |
|---|---|
FIELD_PATTERN | '/^[A-Za-z_][A-Za-z0-9_]*(\\.[A-Za-z_][A-Za-z0-9_]*)?$/' |
MAX_PER_PAGE | 1000 |
MAX_SEARCH_LENGTH | 255 |
LIKE_ESCAPE | '!' |
FILTER_TEXT | 'text' |
FILTER_EXACT | 'exact' |
FILTER_BOOLEAN | 'boolean' |
FILTER_DATE_RANGE | 'dateRange' |
CONTAINS | 'contains' |
GTE | 'gte' |
LT | 'lt' |
Methods
__construct
__construct(int $page = 1, int $perPage = 10, array $sort = [], ?string $search = null, array $filters = [], array $searchFields = [], int $draw = 0, array $conditions = [], array $totals = [], ?string $groupBy = null)Typed filters: `contains` (ignoring case), `gte` (on or after) and `lt` (before). A date
range's last day is included: its `lt` value is the next day.
every row that passes the search and filters.the source counts and totals the groups on the page.$searchFields: Fields the search term applies to; empty lets the source decide.$groupBy: The field rows are grouped by: rows are sorted by it first, and
fromArray
static fromArray(array $query, ?array $sortable = null, ?array $searchable = null, int $defaultPerPage = 10, array $filterTypes = [], array $totals = [], ?string $groupBy = null): selfThese fields are filtered only as their type says, whether searchable or not.the client sorts it descending first.$sortable: Fields the client may sort on; null allows any valid field name.$searchable: Fields searched and allowed as filters; null allows any valid field name.$groupBy: A field to group by: the sort starts with it, ascending unless
offset
offset(): intlikePattern
likePattern(): ?stringThe search term as a "contains" LIKE pattern, with % and _ matched literally. Use it with an explicit escape clause: LIKE ? ESCAPE '!' (see LIKE_ESCAPE).
containsPattern
static containsPattern(string $value): stringA "contains" LIKE pattern for a text (the search term, or a contains condition's value), with % and _ matched literally. Use it with LIKE ? ESCAPE '!'.
isValidField
static isValidField(string $field): boolDataResult
final class Caelrik\Ui\Data\DataResult implements JsonSerializable
One page of rows plus the metadata every Caelrik endpoint returns:
{"data": [...], "meta": {"page", "perPage", "total", "filtered", "draw", "sort", "search", "filters",
"conditions"}}A request with totals adds "totals" (field => value), and one grouped by a field adds "groups": [{"value", "count", "totals"}] for the groups on the page.
Methods
__construct
__construct(array $rows, int $total, int $filtered, DataRequest $request, array $totals = [], array $groups = [])The groups of the page's rows (DataRequest::$groupBy), counted and totalled over the
filtered rows.$total: Row count before search and filters.$filtered: Row count after search and filters, before paging.
map
map(callable $callback): selfReturns a copy with transformed rows (used to project rows onto the declared columns).
toArray
toArray(): arrayjsonSerialize
jsonSerialize(): arrayDataSourceInterface
interface Caelrik\Ui\Data\DataSourceInterface
A source of rows for data-bound components (Grid today, Scheduler and others later).
Field names in the request are already validated against FIELD_PATTERN and the component's whitelist, so implementations may use them as column names.
Methods
fetch
fetch(DataRequest $request): DataResultDateRange
final class Caelrik\Ui\Data\DateRange
The visible date range FullCalendar asks events for: ?start=...&end=... (end exclusive).
Constants
| Constant | Value |
|---|---|
MAX_DAYS | 400 |
Methods
__construct
__construct(DateTimeImmutable $start, DateTimeImmutable $end)fromQuery
static fromQuery(array $query, ?DateTimeZone $timeZone = null): selfoverlaps
overlaps(Event $event): boolWhether an event is at least partly inside the range.
Event
final class Caelrik\Ui\Data\Event implements JsonSerializable
A calendar event, validated on construction and serialized in FullCalendar's format.
All-day events use an exclusive end date, as FullCalendar does: a one-day event on 2026-11-05 has start 2026-11-05 and no end (or end 2026-11-06).
Constants
| Constant | Value |
|---|---|
MAX_TITLE_LENGTH | 255 |
Methods
__construct
__construct(string $title, DateTimeImmutable $start, ?DateTimeImmutable $end = null, bool $allDay = false, string|int|null $id = null, ?string $color = null, ?string $url = null, array $extra = [])fromArray
static fromArray(array $data, ?DateTimeZone $timeZone = null): selfBuilds an event from request data or a database row.
Keys: title, start, end, allDay, id, color, url, extendedProps (or extra). allDay defaults to true when start is a plain date such as "2026-11-05".
toArray
toArray(): arrayjsonSerialize
jsonSerialize(): arraytextColorFor
static textColorFor(?string $color): ?stringBlack or white, whichever contrasts more with a hex color (WCAG relative luminance).
EventResult
final class Caelrik\Ui\Data\EventResult implements JsonSerializable
Events for one date range, in the standard Caelrik envelope:
{"data": [{"id", "title", "start", "end", "allDay"...}], "meta": {"start", "end", "count"}}Methods
__construct
__construct(array $events, DateRange $range)toArray
toArray(): arrayjsonSerialize
jsonSerialize(): arrayEventSourceInterface
interface Caelrik\Ui\Data\EventSourceInterface
A source of calendar events for the Scheduler.
Methods
between
between(DateRange $range): iterableEvents that overlap the range (start inclusive, end exclusive).
InvalidCardMove
final class Caelrik\Ui\Data\InvalidCardMove extends RuntimeException implements Stringable
A move a task board refuses (TaskBoard::cardMove(), or your own rules, e.g. a full column): answer it with a 422 and toArray(); the card goes back and the message is read.
Methods
toArray
toArray(): arrayInvalidCellEdit
final class Caelrik\Ui\Data\InvalidCellEdit extends RuntimeException implements Stringable
A value a grid cell cannot take (Grid::cellEdit()): answer it with a 422 and toArray(), and the grid shows the message in the cell.
Methods
__construct
__construct(string $field, string $message)toArray
toArray(): arrayThe answer the grid reads: {"message": "...", "errors": {"field": ["..."]}}, as Laravel answers a failed validation.