How to place a navigation element without a group between groups or after?
Hello.
The $navigationSort variable does not work in the Cluster. Why?
<?php
namespace App\Filament\Clusters;
use Filament\Clusters\Cluster;
class Settings extends Cluster
{
protected static ?string $navigationIcon = 'heroicon-o-squares-2x2';
protected static ?int $navigationSort = 1;
}
39 Replies
Current positions:
Dashboard
Settings
- Blog Group
-> ...
- Shop Group
-> ...
I want to move the Settings element to the very end. How to do it?
Dashboard
- Blog Group
-> ...
- Shop Group
-> ...
Settings
put this in other 2 as well
your code will be like this
Blog Group:- protected static ?int $navigationSort = 1;
Shop Group:- protected static ?int $navigationSort = 2;
Settings:- protected static ?int $navigationSort = 3;
Groups do not have $navigationSort. Only elements within a group have this.
The Settings element is not a group. It is in the null group along with the Dashboard element.
I think you need to make navigation group of it and then do this in your app/Providers/Filament/AdminPanelProviders.php
->navigationGroups([
NavigationGroup::make()
->label('Job Pool System'),
NavigationGroup::make()
->label('Authorization System'),
NavigationGroup::make()
->label('Attendance / Activity System'),
NavigationGroup::make()
->label('Leave Management System'),
NavigationGroup::make()
->label('Project Management System'),
NavigationGroup::make()
->label('Issue Tracking System'),
NavigationGroup::make()
->label('Pay Roll'),
NavigationGroup::make()
->label('Configuration'),
])
there is no other way
No. This option is not suitable because a group with a name will be created for the Settings element. I don't need to store the Settings element in a group. I need to store it without a group and at the very bottom of the navigation.
can you not just add a custom nav item to the sidebar on the panel?
No. This is also not true. No need for a group. The Settings button should be without a group and at the very bottom of the navigation.
you can modify it and remove the group
->navigationItems([
NavigationItem::make('Theme')
->url(function () {
return route('your route'); }) ]) use the sort to place it where you need alternatively use a renderhook
return route('your route'); }) ]) use the sort to place it where you need alternatively use a renderhook
This doesn't solve the problem. The Theme element also cannot be moved to the very end of the navigation, after all the groups.
->renderHook(
PanelsRenderHook::SIDEBAR_NAV_FOOTER,
fn(): View => view('filament/PanelName/navigation/exit-settings'),
)
https://filamentphp.com/docs/3.x/support/render-hooks#panel-builder-render-hooks
then on view something like
This doesn't solve the problem either. Using a hook violates the integrity of the menu. The element should remain a navigation element.
read the render hooks
you can do it in the nav element
PanelsRenderHook::SIDEBAR_NAV_END - In the sidebar, before </nav>
How do I specify PanelsRenderHook::SIDEBAR_NAV_END in the Settings Resource?
you dont, you do it in the panel
as a render hook
But then the button will not become active. Navigation concept breaks down
have you tried it?
you can put logic to change the state when you are on the url
Why can't I place Menu Items without groups between other groups or after?
It is very strange
What if I want to place a navigation element between two groups. RenderHook will not help in this case.
you can publish your sidebar and customise it - or override the nav all together as per docs
https://filamentphp.com/docs/3.x/panels/navigation#grouping-navigation-items-under-other-items
https://filamentphp.com/docs/3.x/panels/navigation#registering-custom-navigation-items
Sometimes we have to live within the limitations of the tools we use . Filament is incredibly flexible and you have been given multiple potential solutions - if none of them are an exact fit for your needs then you may need to adapt your expectations and requirements
These documentation links do not solve the navigation element position issue. (
My expectations are as simple and intuitive as possible. But for some reason Filament won’t allow you to do this without using crutches.
Sorry i have given you all the ideas I have, and as @Blackpig says...
i would read this https://filamentphp.com/docs/3.x/panels/navigation#advanced-navigation-customization to get complete control of your nav
this will completely override the nav and you can do what you wish with it
>navigation(function (NavigationBuilder $builder): NavigationBuilder {
return $builder->items([
NavigationItem::make('Dashboard')
->icon('heroicon-o-home')
->isActiveWhen(fn (): bool => request()->routeIs('filament.admin.pages.dashboard'))
->url(fn (): string => Dashboard::getUrl()),
....
I tried this method. The problems remain the same. I can't move the Settings resource after all groups. (
->navigation(function (NavigationBuilder $builder): NavigationBuilder {
$builder= $builder->items([
...MainResource::getNavigationItems(),
...SettingsResource::getNavigationItems()
]);
$builder= $builder->groups([
NavigationGroup::make('Blog')
->items([
...PostResource::getNavigationItems(),
...CategoryResource::getNavigationItems()
]),
]);
return $builder;
})
The only solution that comes to mind is to add the Settings navigation element to the Settings group and hide the title of this group using CSS. This is a crutch solution, but this way I can move the Navigation Element to the very end of the list... But I don’t like this solution...ok last attempt for me - so on your clusters do you have protected static ?int $navigationSort = 1;
Yes
ok and on your settings resource?
And it doesn't affect anything. Because navigation elements without a group are in the "null" group... And the sorting happens inside the "null" group.
I need the Settings navigation element to have its own separate "null" group, in which case I can move it to the end. But how to do that?
Here is a clear example of what is required.
Is there a solution to this problem?
hum.. I think you can't..
I have an idea how to do this within the CustomerResource.php class using a crutch method. I'll try tomorrow, if it's successful I'll send you the code.
From the docs. “Ungrouped items will remain at the start of the navigation.”
If you absolutely need this behavior in Filament it will require a PR.
Thank you for this info ✌️
I have developed two solutions to this problem.
First solution:
Override the
getNavigationItems()
method in resources or pages. (For convenience, you can create a trait)
public static function getNavigationItems(): array
{
$navigationGroup = str(class_basename(static::class) . 'Group')->kebab()->lower();
filament()->getCurrentPanel()->navigationGroups([
NavigationGroup::make()
->label($navigationGroup)
->collapsible(false)
->extraSidebarAttributes(['class' => '[&_.fi-sidebar-group-button]:hidden'])
]);
return [
parent::getNavigationItems()[0]
->group($navigationGroup)
];
}
And then using $navigationSort
the navigation element can be placed at any navigation position.
Second solution:
In the AdminPanelProvider.php
file add
$panel
// ...
->navigationGroups([
NavigationGroup::make()
->label('nav-end')
->collapsible(false)
->extraSidebarAttributes(['class' => '[&_.fi-sidebar-group-button]:hidden'])
])
And then in the necessary resources and pages we add
protected static ?string $navigationGroup = 'nav-end';
In this case, you can place multiple navigation elements at the end of the navigation.