# Collections & arrays

> Build tables from bounded in-memory data.

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

Pass an array or collection when the data is already in memory:

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

Table::make('activity')
    ->data([
        ['id' => 1, 'event' => 'Account created'],
        ['id' => 2, 'event' => 'Profile updated'],
    ])
    ->addColumns([
        NumberColumn::make('id')->numberCast('int')->visible(false),
        TextColumn::make('event')->searchable()->sortable(),
    ]);
```

Return and render this table [through Inertia](https://docs.inertiax.dev/table/guide/inertia/) as usual.

## Execution and size

Arrays become Laravel collections. Eloquent collections remain in-memory snapshots; InertiaX does not turn them back into database queries.

Filters, search, and sorting process the full collection before pagination slices it. Use an Eloquent builder for large database datasets so those operations stay in SQL.

## Identity and inference

Plain rows default to an `id` key. A nonempty collection whose first item is an Eloquent model uses that model’s primary key. For custom model keys, set `rowKey()` explicitly if the collection can be empty. Declare the key as a column even when there are no rows.

Automatic columns need a resolvable Eloquent model. Use explicit columns for arrays, plain objects, and empty collections.

## Custom comparisons

Built-in comparisons support both Eloquent and collections. Custom sorting, search, clause, and option callbacks must declare `DataSourceKind::Collection` and implement collection behavior. See [Custom query behavior](https://docs.inertiax.dev/table/guide/query-callbacks/).
