Adding an additional item to the grouping
Hello folks! I'm currently trying out this grouping feature in Filament 3 and I've just got a specific question.
I have pages that are grouped by a parentPages relation. To be clear: In my case, pages can get a parent page.
The grouping works great, but I would like to have the parent page listed in this grouping as well and not individually in a different place of the table.
How do I trick the grouping so that the parent page is also included in the grouping? Any idea? I did not find anything in the documentation. Or I have missed it 🫤
//Edit:
An example in the screenshot: I would like to be able to find "Third Page" also in the grouping named "Third Page" and not way above the grouping as it is in the screenshot.
Solution:Jump to solution
```php
->prefix(function (Page $record, Table $table): ?Htmlable {
if (! static::shouldShowParent($table) && $record->parent) {
return new HtmlString('<span style="margin-inline-end: 0.75rem;">└</span>');...
16 Replies
Are you trying to do something like how Wordpress displays it’s pages?
Well, the last time I saw the Wordpress Backend was 3 years ago. What exactly do you mean? :D
Oh wait, I know what you might mean. That "tree structure" from Wordpress, right? That's more or less what I wanted it to look like
Yea. There was a good help thread about this. No real solution though. Be cause it falls apart with filters/searching. Was trying to find it for you but the discord search on mobile is complete crap.
I did manage to get something that works similar to how Wordpress is doing it.
But it was posted in that thread I can’t find right now.
Solution
First block goes on the column
This looks like it only affects the title column and not a grouping, right? I would give it a try and it would be an option to me
Yea. It won’t work with grouping, that was discussed in that thread.
I can’t think of a way to show the grouped parent since they are the same type of record.
And that’s how it’s being grouped is by a parent id.
That worked for me, thanks a lot! :)
But I guess this is from v2? Because
->prefix()
can't output Html for me. Only strings. Or did i miss something?It’s v3
The new HtmlString converts it to a sting
Make sure you imported Htmlable and HtmlString
Mh okay thats weird. It converts to a string but the output is not formatted as html. Everything seems right to me
Weird.
Oh my mistake. I should have used ->html() in the column xD
Makes sense. Sorry. Mine is on BadgeableColumn from a plug-in that is probably handling that by default.
Glad it works for you though.
Nevermind. But thanks anyway for your time and help. Have a great night :)
You too.