# Creating tables

> Define a table inline or reuse a Laravel table class.

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

Use an inline definition for a small, page-specific table:

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


Table::make('users')
    ->data($users)
    ->addColumns([
        NumberColumn::make('id')->numberCast('int')->visible(false),
        TextColumn::make('name')->searchable()->sortable(),
    ]);
```

`$users` is the query for this page. Include the row’s primary key among the columns, even when it is hidden. See [Data sources](https://docs.inertiax.dev/table/guide/data-sources/#row-identity) for other key fields.

## Reuse a table class

Move shared columns and settings into a class:

app/Tables/UsersTable.php

```php
<?php

namespace App\Tables;

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

class UsersTable extends Table
{
    protected static int $defaultPageSize = 25;

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

Supply the query when returning the table:

```php
use App\Tables\UsersTable;
use Inertia\Inertia;

return Inertia::render('users/index', [
    UsersTable::make('users')->data($users),
]);
```

Render it with `<AppTable prop="users" />`. The name passed to `make()` identifies this instance, so the same class can serve [multiple tables](https://docs.inertiax.dev/table/guide/multiple-tables/).

## Override one instance

```php
UsersTable::make('users')
    ->data($users)
    ->replaceColumn(TextColumn::make('email', 'Work email')->copyable())
    ->pageSize(50);
```

Fluent calls apply after the class definition. A class can also declare its own [`data()` method](https://docs.inertiax.dev/table/guide/data-sources/#define-data-in-the-class) and [`filters()` method](https://docs.inertiax.dev/table/guide/filters/#declare-a-filter).

See [Table inheritance](https://docs.inertiax.dev/table/guide/table-inheritance/) for composing definitions and [Table API](https://docs.inertiax.dev/table/reference/table/) for the full builder reference.
