# Columns

> Choose InertiaX cell types, format values, and enable column controls in Laravel.

Source: https://docs.inertiax.dev/table/guide/columns/

Add columns with a field key and an optional label:

```php
use InertiaX\Table\Columns\NumberColumn;
use InertiaX\Table\Columns\TextColumn;

protected function columns(): array
{
    return [
        NumberColumn::make('id')->numberCast('int')->visible(false),
        TextColumn::make('name', 'Full name')->searchable()->sortable(),
        TextColumn::make('email')->copyable(),
    ];
}
```

## Choose a cell type

| Column           | Displays                          |
| ---------------- | --------------------------------- |
| `TextColumn`     | Text                              |
| `NumberColumn`   | Integers or decimals              |
| `BooleanColumn`  | A Boolean label and optional icon |
| `DateColumn`     | A date                            |
| `DateTimeColumn` | A date and time                   |
| `TimeColumn`     | A time                            |
| `JsonColumn`     | Formatted structured data         |
| `BadgeColumn`    | A status or category badge        |

All classes are in `InertiaX\Table\Columns`.

```php
BooleanColumn::make('active')->trueLabel('Enabled')->falseLabel('Disabled');
DateColumn::make('joined_on', 'Joined')->format('M j, Y');
BadgeColumn::make('status')->variant([
    'active' => 'success',
    'invited' => 'secondary',
]);
```

## Format numbers and currencies

```php
NumberColumn::make('amount_cents', 'Amount')
    ->numberCast('int')
    ->currency('USD', divideBy: 100)
    ->copyable();

NumberColumn::make('ratio')->numberCast('decimal')->decimals(3)->locale('fr-FR');
```

The first column displays `8419` as `$84.19` in the cell, title and copied text. Its raw value stays `8419`. Formatting defaults to `en-US`; choose a locale explicitly when needed.

Use `int` for integer units and `decimal` for exact decimal strings. Formatting cannot recover precision already lost by a float cast. Filters still accept stored units: label a cents filter **Amount (cents)**. See [Number presentation](https://docs.inertiax.dev/table/reference/column/#number-presentation) for options and how formatting interacts with value transformers.

## Show a related field

For an order’s customer name, use its `customer()` BelongsTo relation:

```php
TextColumn::make('customer_name', 'Customer')
    ->relationship('customer', 'name')
    ->searchable()
    ->sortable();
```

On a customer table, use its `orders()` HasMany relation for totals:

```php
NumberColumn::make('orders_count', 'Orders')->count('orders')->sortable();
```

See [related fields](https://docs.inertiax.dev/table/reference/column/#related-scalar-fields) and [counts and sums](https://docs.inertiax.dev/table/reference/column/#relationship-counts-and-sums) for supported relations and options.

## Enable controls

Opt into [search](https://docs.inertiax.dev/table/guide/search/), [sorting](https://docs.inertiax.dev/table/guide/sorting/), [filtering](https://docs.inertiax.dev/table/guide/filters/), copying, or the [column picker](https://docs.inertiax.dev/table/guide/column-visibility/):

```php
TextColumn::make('email')
    ->searchable()
    ->sortable()
    ->filterable()
    ->copyable()
    ->toggleable();
```

Use `wrap()` for wrapping text or `truncate(80)` to shorten a displayed value.

## Transform values

```php
TextColumn::make('name')
    ->transformUsing(fn (string $value): string => mb_strtoupper($value));

TextColumn::make('role')->mapAs([
    'admin' => 'Administrator',
    'member' => 'Member',
], default: 'Unknown');
```

Use `$value` for the scalar argument: its name matters, and there is no positional injection. Typed record arguments can use any name. See [Callback context](https://docs.inertiax.dev/table/reference/callbacks/).

Transformers run on the server when preparing cells. Search and sorting still operate on source values. See [Custom columns](https://docs.inertiax.dev/table/guide/custom-columns/) for row metadata and React renderers.

## Infer columns from a model

```php
Table::make('users')->data($users)->autoColumns();
```

`autoColumns()` shows the fields the model serializes, as `toArray()` does: its columns and `$appends`, without `$hidden` fields, or only the `$visible` ones when that list is set. Leave a field out of one table with `autoColumns(except: ['internal_notes'])`. An explicitly added column with the same key replaces the inferred one and appears after the inferred columns. Use `AutoColumn::make('score')->sortable()` to infer just one field.

Caution

Review the model’s inferred fields before exposing the table. See [Field exposure](https://docs.inertiax.dev/table/guide/security/#choose-fields-deliberately).

See [Column API](https://docs.inertiax.dev/table/reference/column/) for options, defaults, and inference rules.

## Callback context

Callback parameters are injected by name or object type. See the [callback reference](https://docs.inertiax.dev/table/reference/callbacks/) for the complete argument list and resolution rules.
