SortState
API reference › Debug Core › View › Grid › SortState
Represents the active sort attribute and direction parsed from the sort query value.
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$attribute readonly constructor | string | Attribute the rows are ordered by. | SortState |
$direction readonly constructor | "asc"| | Order applied to the attribute. | SortState |
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
apply() | Sorts rows with the natural ascending comparator, inverted for desc, then breaks ties in a fixed order. | SortState |
fromQuery() static | Parses the query value, keeping it only when the attribute is sortable; otherwise applies the default. | SortState |
header() | Builds the header cell of a sortable column, linking to the order the next click on it requests. | SortState |
panelUrl() static | Builds the header-link factory of a panel grid, carrying the query parameters of the visible page. | SortState |
Method details
Section titled “Method details”apply()
Section titled “apply() ”public function apply(list<PHPForge\Debug\View\Grid\TRow> $rows, Closure(PHPForge\Debug\View\Grid\TRow, PHPForge\Debug\View\Grid\TRow): int $compare, Closure(PHPForge\Debug\View\Grid\TRow, PHPForge\Debug\View\Grid\TRow): int|null $tieBreak = null): list<PHPForge\Debug\View\Grid\TRow>Sorts rows with the natural ascending comparator, inverted for desc, then breaks ties in a fixed order.
Parameters
| Parameter | Type | Description |
|---|---|---|
$rows | list<PHPForge\ | Rows to order. |
$compare | Closure(PHPForge\ | Ascending comparator for the active attribute. |
$tieBreak | Closure(PHPForge\ | Direction-independent comparator applied to rows the main comparator considers equal, or null to keep their relative input order. |
Returns
list<PHPForge\Debug\View\Grid\TRow>: Ordered rows.
fromQuery()
Section titled “fromQuery() ”public static function fromQuery(string|null $sort, list<string> $attributes, string $defaultAttribute, "asc"|"desc" $defaultDirection = 'asc'): selfParses the query value, keeping it only when the attribute is sortable; otherwise applies the default.
Parameters
| Parameter | Type | Description |
|---|---|---|
$sort | string| | Raw sort query value, optionally prefixed with - to request a descending order. |
$attributes | list<string> | Sortable attribute names. |
$defaultAttribute | string | Attribute used when the query value names no sortable attribute. |
$defaultDirection | "asc"| | Direction paired with the default attribute. |
Returns
self: Sort state for the visible page.
header()
Section titled “header() ”public function header(string $attribute, string $label, Closure(string): string $url, bool $descendingFirst = false): PHPForge\Debug\View\Grid\SortHeaderBuilds the header cell of a sortable column, linking to the order the next click on it requests.
Parameters
| Parameter | Type | Description |
|---|---|---|
$attribute | string | Attribute backing the header cell. |
$label | string | Visible column label. |
$url | Closure(string): string | Builds the panel URL requesting a sort query value. |
$descendingFirst | bool | Whether the first click on an inactive attribute requests a descending order. |
Returns
SortHeader: Header cell announcing the active order.
panelUrl()
Section titled “panelUrl() ”public static function panelUrl(PHPForge\Debug\Panel\PanelRenderContext $context, array<array-key, mixed> $queryParams): Closure(string): stringBuilds the header-link factory of a panel grid, carrying the query parameters of the visible page.
Parameters
| Parameter | Type | Description |
|---|---|---|
$context | PHPForge\ | State of the debugger request being rendered. |
$queryParams | array<array-key, | Query parameters the header links are built from. |
Returns
Closure(string): string: Builds the panel URL requesting a sort query value.