F
Filamentβ€’3mo ago
Tony

Reflect Table Interactions in Form State

How can I catch checkbox changes or modify the array data? I'm using a custom Table component inside a form and want to reflect any checkbox updates directly into the component's $data property.
public function table(Tables\Table $table): Tables\Table
{
return $table
->records(function () {
return [
[
'id' => 1,
'checked' => false,
'title' => 'title',
],
];
})
->columns([
Tables\Columns\TextColumn::make('id'),
Tables\Columns\CheckboxColumn::make('checkbox'),
Tables\Columns\TextColumn::make('title'),
]);
}
public function table(Tables\Table $table): Tables\Table
{
return $table
->records(function () {
return [
[
'id' => 1,
'checked' => false,
'title' => 'title',
],
];
})
->columns([
Tables\Columns\TextColumn::make('id'),
Tables\Columns\CheckboxColumn::make('checkbox'),
Tables\Columns\TextColumn::make('title'),
]);
}
This table is rendered inside a form like so:
public ?array $data = [];

public function form(Schemas\Schema $schema): Schemas\Schema
{
return $schema
->components([
Infolists\Components\ViewEntry::make('products')
->view('filament.components.order-products', [
'table' => $this->table(Tables\Table::make($this))
]),
])
->statePath('data');
}
public ?array $data = [];

public function form(Schemas\Schema $schema): Schemas\Schema
{
return $schema
->components([
Infolists\Components\ViewEntry::make('products')
->view('filament.components.order-products', [
'table' => $this->table(Tables\Table::make($this))
]),
])
->statePath('data');
}
<!-- order-products.blade.php -->
<div>
{{ $table }}
</div>
<!-- order-products.blade.php -->
<div>
{{ $table }}
</div>
Is there any built-in way to react to changes in the table (especially checkbox/input/select) so that $this->data is updated accordingly? Any advice or workaround would be appreciated πŸ™
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?