Columns overview
Defining columns on TableAbstract
Columns are how you tell the frontend what to show in each cell. They are defined in the $TBLColumns array on your table class and returned in the load-table response after normalization.
Minimal mental model
Database row → data_src maps field → type picks renderer → JSON to frontendYou control the mapping; the package controls JSON shape; the frontend controls visual styling.
Basic column
protected array $TBLColumns = [
[
'type' => 'text', // how to render
'label' => 'name', // translation key + header id
'data_src' => 'name', // Eloquent attribute
'sortable' => true, // allow sort in query-table
'attributes' => [
'showable' => true, // false = hidden column
'showInMobileApp' => true,
'minWidth' => 120, // UI hint (pixels)
],
],
];Column definition fields
| Field | Required | Description |
|---|---|---|
type | Yes | Renderer key — Column types |
label | Yes | Becomes __('api-table.{tableName}.{label}') |
data_src | Yes* | Model attribute or relation path |
sortable | No | Default false — set true for sortable columns |
attributes | No | UI hints, formatting, visibility |
callBack | No | Method on table class for computed values |
*Action columns may use name instead of data_src.
Relations (dot notation)
'data_src' => 'category.name'Internally becomes category__name in query results. Ensure the relation is loaded:
protected function setInitialBuilder(): void
{
$this->builder = $this->model::query()->with('category');
}Computed columns (callbacks)
When the displayed value is not a raw DB column:
[
'type' => 'text',
'label' => 'status_label',
'data_src' => 'status',
'callBack' => 'formatStatus',
],public function formatStatus($item, $value): string
{
return match ($value) {
'active' => 'Active',
'pending' => 'Pending',
default => 'Unknown',
};
}The method name in callBack must exist on your table class (provided via TableCallBacks trait on TableAbstract).
Conditional columns
Hide a column based on runtime context:
'attributes' => [
'loadIf' => auth()->user()->isAdmin(),
],Or add to $unLoadableColumns programmatically in the constructor.
Default sort
public string $defSortCol = 'created_at';
public string $defSortDir = 'desc';Returned in structure JSON; used when client sends empty sorts.
Walkthrough: adding a column
Add to $TBLColumns
['type' => 'text', 'label' => 'phone', 'data_src' => 'phone', 'sortable' => false],Add translation
// lang/en/api-table.php → 'users' => ['phone' => 'Phone number']Deploy and reload structure
Frontend must re-fetch load-table — new column appears.
Verify in query response
phone key should appear in each items[] object.