Skip to content
Zonvoir Table LogoZonvoir Table

Column Base Class API Reference

Zonvoir\ZonvoirTable\Columns\Column is the abstract base class for backend column definitions. Concrete column classes include TextColumn, NumericColumn, BooleanColumn, BadgeColumn, ImageColumn, DateColumn, DateTimeColumn, SerialNumberColumn, and ActionColumn.

Item Value
Class Zonvoir\ZonvoirTable\Columns\Column
Type abstract class
Constructor protected function __construct(string $name)
Factory methods make(), create()
public static function make(
string $name,
string|callable|null $label = null,
bool $sortable = false,
bool $toggleable = true,
bool $searchable = false,
string|ColumnAlignment|null $alignment = null,
?callable $mapAs = null,
bool $visible = true,
?callable $sortUsing = null,
array $meta = [],
bool $sticky = false,
?callable $searchUsing = null,
?string $key = null,
?string $labelClass = null,
?string $cellClass = null,
false|callable|null $exportAs = null,
string|callable|null $exportLabel = null,
?string $exportFormat = null,
array|callable|null $exportStyle = null,
): static

create() accepts the same arguments and delegates to make().

type()

Signature

public function type(): string

Infer the serialized type from the concrete class name.

name()

Signature

public function name(): string

Return the backend field name.

key()

Signature

public function key(?string $key): static

Override the serialized key.

label()

Signature

public function label(string|callable|null $label): static

Set the display label. Label callbacks are invoked with no arguments.

visible()

Signature

public function visible(bool $visible = true): static

Set initial visibility.

toggleable()

Signature

public function toggleable(bool $toggleable = true): static

Disable user column toggling when passed `false`.

sticky()

Signature

public function sticky(bool $sticky = true): static

Mark the column as sticky in metadata.

alignment()

Signature

public function alignment(string|ColumnAlignment|null $alignment): static

Set alignment metadata.

width()

Signature

public function width(string|int|null $width): static

Set width metadata.

minWidth()

Signature

public function minWidth(string|int|null $minWidth): static

Set minimum width metadata.

maxWidth()

Signature

public function maxWidth(string|int|null $maxWidth): static

Set maximum width metadata.

labelClass()

Signature

public function labelClass(?string $labelClass): static

Set header label class metadata.

cellClass()

Signature

public function cellClass(?string $cellClass): static

Set cell class metadata.

tooltip()

Signature

public function tooltip(?string $tooltip): static

Add tooltip metadata.

defaultValue()

Signature

public function defaultValue(mixed $defaultValue): static

Add fallback value metadata.

meta()

Signature

public function meta(array $meta): static

Merge arbitrary adapter metadata.

searchable()

Signature

public function searchable(bool $searchable = true): static

Enable column search metadata.

searchUsing()

Signature

public function searchUsing(?callable $callback): static

Register a custom search callback.

searchCallback()

Signature

public function searchCallback(): ?Closure

Return the configured search callback.

isSearchable()

Signature

public function isSearchable(): bool

Inspect searchable state.

sortable()

Signature

public function sortable(bool $sortable = true): static

Enable sort metadata.

sortUsing()

Signature

public function sortUsing(?callable $callback): static

Register a custom sort callback.

sortCallback()

Signature

public function sortCallback(): ?Closure

Return the configured sort callback.

isSortable()

Signature

public function isSortable(): bool

Inspect sortable state.

mapAs()

Signature

public function mapAs(?callable $mapAs): static

Transform a cell value.

resolveValue()

Signature

public function resolveValue(mixed $record): mixed

Resolve `data_get($record, $name)` and apply `mapAs()`.

url()

Signature

public function url(string|Url|callable|null $url): static

Configure cell URL metadata.

resolveUrl()

Signature

public function resolveUrl(mixed $record): string|array|null

Resolve string, `Url`, or callback URL metadata.

image()

Signature

public function image(string|callable|null $image, ?callable $configure = null): static

Configure image metadata.

resolveImage()

Signature

public function resolveImage(mixed $record): ?array

Resolve image configuration to serialized metadata.

mapAs() callbacks are invoked as fn (mixed $value, mixed $record): mixed.

URL callbacks are invoked as fn (mixed $record, Url $url): string|Url|array|null.

Image callbacks support either record-first or Image-first parameters. The implementation accepts fn ($record), fn ($record, Image $image), fn (Image $image), or fn (Image $image, $record).

export()

Signature

public function export(array $configuration): static

Store arbitrary export metadata on the column.

exportAs()

Signature

public function exportAs(false|callable|null $exportAs = null): static

Transform the value used by generated exports, or disable export with `false`.

exportFormat()

Signature

public function exportFormat(?string $format): static

Set column format metadata.

exportStyle()

Signature

public function exportStyle(array|callable|null $style): static

Set static or callback style metadata.

exportLabel()

Signature

public function exportLabel(string|callable|null $label): static

Override the export heading label.

dontExport()

Signature

public function dontExport(bool $condition = true): static

Exclude this column from generated exports.

isExportable()

Signature

public function isExportable(): bool

Inspect exportable state.

resolvedExportLabel()

Signature

public function resolvedExportLabel(): string

Resolve export heading text.

resolveExportValue()

Signature

public function resolveExportValue(mixed $record): mixed

Resolve the value passed to export rows.

resolvedExportFormat()

Signature

public function resolvedExportFormat(): ?string

Resolve export format metadata.

resolvedExportStyle()

Signature

public function resolvedExportStyle(mixed $sheet = null): ?array

Resolve export style metadata.

exportAs() callbacks are invoked as fn (mixed $value, mixed $record): mixed.

exportStyle() callbacks are invoked as fn (mixed $sheet, Column $column): ?array.

toArray() serializes the column key, name, type, label, visibility, search/sort/toggle/sticky flags, alignment, sizing, classes, default value, export metadata, arbitrary metadata, and optional tooltip.