Search
In addition to the extensive filtering options, Inertia Table offers a global search field that performs a wildcard search across one or more columns.
Enabling via the Column Class
One way to enable global search is by passing the searchable argument to the column's make() method:
TextColumn::make('name', searchable: true);Alternatively, you may use the searchable() and notSearchable() methods:
TextColumn::make('name')->searchable();
TextColumn::make('name')->notSearchable();Enabling via the Table Class
Another way to enable global search is by setting the $searchable property on your Table class:
class Users extends Table
{
protected array|string $search = ['name', 'email'];
}Customizing the Search Query
You may customize the search query via the withQueryBuilder() method, which lets you interact with the built-in Query Builder before the results are fetched. On the QueryBuilder instance, call searchUsing() to customize the search query. The callback receives the Eloquent Query Builder, the raw search term as a string, and the search terms parsed into a Collection.
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Collection;
use InertiaUI\Table\QueryBuilder;
class Users extends Table
{
public function withQueryBuilder(QueryBuilder $queryBuilder): ?QueryBuilder
{
$queryBuilder->searchUsing(function (Builder $query, string $search, Collection $terms) {
$locale = app()->getLocale();
$query->where("name->{$locale}", 'like', "%{$search}%");
});
return $queryBuilder;
}
}Take care to handle empty search terms yourself.
Autofocus
By default, the global search field is focused on page load. To disable this, set the $autofocus property to TableComponent::None:
use InertiaUI\Table\TableComponent;
class Users extends Table
{
protected ?TableComponent $autofocus = TableComponent::None;
}To set this as the default for all tables, call the static defaultAutofocus() method on the Table class, typically in your AppServiceProvider:
use InertiaUI\Table\Table;
use InertiaUI\Table\TableComponent;
Table::defaultAutofocus(TableComponent::None);