F
Filament15mo ago
sm

Forcing a TableWidget to refresh its builder query.

Hey there! I'm trying to figure out the best way to handle this: I have a Resource with a form that has some filters, the filters apply to an unrelated model (i.e, not the Model associated with that form). Users can add/remove filters using a Repeater. I'd like to show them the results of applying the filters, so I decided to use a simple ViewField to load a "dynamic" TableWidget, basically it shows the data from the other model (it's super simple, just extending TableWidget). The blade for the viewfield looks like:
@livewire(
\App\Filament\Widgets\DynamicTableWidget::class,
[
'modelClass' => SomeModel::class
'pageClass' => static::class]
)
@livewire(
\App\Filament\Widgets\DynamicTableWidget::class,
[
'modelClass' => SomeModel::class
'pageClass' => static::class]
)
The table() in the DynamicTableWidget is:
$model = new $this->modelClass;
$columns = $model->getFillable();
$fields = [];

foreach ($columns as $column) {
$fields[] = Tables\Columns\TextColumn::make($column)->wrap();
}

return $table
->query($model::query())
->columns($fields)
$model = new $this->modelClass;
$columns = $model->getFillable();
$fields = [];

foreach ($columns as $column) {
$fields[] = Tables\Columns\TextColumn::make($column)->wrap();
}

return $table
->query($model::query())
->columns($fields)
When users update the filters on the main form, I'd like to pass a new builder (with those filters applied) to the table and force it to refresh.. any ideas?
Solution:
Well, that was actually really easy: just dispatch an event from the form and add a listener in the TableWidget.
Jump to solution
1 Reply
Solution
sm
sm15mo ago
Well, that was actually really easy: just dispatch an event from the form and add a listener in the TableWidget.
Want results from more Discord servers?
Add your server