Collapse All Table Row Groups By Default
im trying to figure out if there is a way to collapse all groups by default in a filament table with groups + summaries
is it possible? https://github.com/filamentphp/filament/discussions/10717
19 Replies
bump
Had a similar use case and couldn’t find a way to collapse groups on default. However I managed to create a satisfactory workaround. Ditch the filament groups. Modify the query. Add a custom view column containing a collapsible panel and put your group contents inside. You’ll need to handle summary logic yourself
As added benefit you can lazy load the desired group content only when expanded so the table will be much faster
hmm. @tim.lalev can u give me a little example on how to start implementing it plz?
Sure
For the table columns you can do something like that:
Inside the collapsible custom view column you would put a livewire component responsible for handling the group data.
Make sure to generate a unique livewire key otherwise it will glitch when you collapse/expand the content.
Here is an example:
When you add the 'lazy' => true then livewire will load the content only when visible on the screen (which happens when you expand the column content)
thanks for the workaround. but then, if i do it this way, the items inside the split lose the label, how u handle that?
Ah yeah so for labels you have multiple options.
The simplest is to use description() instead of a label.
It accepts a second parameter for posittion that can eaither be 'above' or 'below'
The other option is to return an infolist from the livewire componet so that you can structure is however you want
You can even render a whole new table from the livewire component if you really need lots of structured data to be shown
Here is a sample of an infolist returned by the livewire component for expanded section
looks really cool
Looks nice and performance is really good
it reminds me like a modal, but is like inside the row. lets see if i manage to get something similar. so far, thanks, really appreciate it
You are welcome! Share your results
yeah for sure
I felt alone in the universe when trying to figure it out hahah good luck
Me and @Min Min Tun faced a similar issue and found a quick solution by extending the Filament vendor file
vendor/filament/tables/resources/views/components/group/header.blade.php
. Then replace
with
This ensures that all groups are collapsed by default.