I’m encountering an issue with FilamentPHP’s TableWidget where the groupsOnly method isn’t updating the table state correctly when a user selects a grouping option.
Context:
I have a TaskReport widget that utilizes the TableWidget to display task data. The table allows users to group tasks by various criteria like ‘senior,’ ‘accountant,’ etc.
The widget code:
class TaskReport extends BaseWidget
{
// ... other code
#[Url]
public ?string $tableGrouping = null;
public function table(Table $table): Table
{
return $table
->query(TaskResource::getEloquentQuery())
->defaultPaginationPageOption(5)
->defaultSort('created_at', 'desc')
->groupsOnly(!empty($this->tableGrouping)) // This line
->groups([
'senior',
'accountant',
'company_area',
])
->columns([
TablesColumnsTextColumn::make('senior')
->sortable(),
TablesColumnsTextColumn::make('accountant')
->searchable()
->sortable(),
TablesColumnsTextColumn::make('company_area')
->searchable()
->sortable(),
TablesColumnsTextColumn::make('workload')
->summarize(Sum::make())
])
->striped()->deferLoading();
}
}
Expected Behavior:
When a user selects a grouping option (e.g., ‘senior’), the table should only display the summary of each group instead of individual tasks.This means that the table should show in this case, only the workload totals for each grouping.Additionally, when the user deselects the grouping option, the groupsOnly method should be set to false, and the table should revert to displaying all tasks.
Actual Behavior:
However, selecting a grouping option doesn’t update the table state as expected. The table either continues to display all tasks. This persists until the user manually reloads the page.
Aditional notes:
-
Investigated Component State: I’ve analyzed the state of the “TaskReport” component using Laravel debugBar, specifically the “Livewire” tab, to observe the state of each element. The “tableGrouping” property updates correctly when a grouping option is selected. However, there doesn’t seem to be any property explicitly indicating the state of “groupsOnly.”
-
Removed deferLoading: I’ve tried removing the deferLoading option from the table configuration, but the issue persists. This suggests that the problem isn’t related to the lazy loading of the table data.
Versions:
- PHP: ^8.2
- Filament/Filament: 3.2.71
- Laravel/Framework: 11.5.0
Emmanuel Fernandez is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.