F
Filament2mo ago
WEBMAS

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
WEBMAS
WEBMAS2mo ago
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
samran2000
samran20002mo ago
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;
WEBMAS
WEBMAS2mo ago
Groups do not have $navigationSort. Only elements within a group have this.
WEBMAS
WEBMAS2mo ago
The Settings element is not a group. It is in the null group along with the Dashboard element.
samran2000
samran20002mo ago
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
WEBMAS
WEBMAS2mo ago
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.
cvc
cvc2mo ago
can you not just add a custom nav item to the sidebar on the panel?
->navigationItems([
NavigationItem::make('Theme')
->url(function () {
//return route('filament.org-settings.pages.themes', organization());
return route('filament.agencySettings.pages.themes', Filament::getTenant());
})
->icon('heroicon-o-presentation-chart-line')
->group('Appearance')
->sort(3),...
->navigationItems([
NavigationItem::make('Theme')
->url(function () {
//return route('filament.org-settings.pages.themes', organization());
return route('filament.agencySettings.pages.themes', Filament::getTenant());
})
->icon('heroicon-o-presentation-chart-line')
->group('Appearance')
->sort(3),...
WEBMAS
WEBMAS2mo ago
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.
cvc
cvc2mo ago
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
WEBMAS
WEBMAS2mo ago
This doesn't solve the problem. The Theme element also cannot be moved to the very end of the navigation, after all the groups.
cvc
cvc2mo ago
->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
<x-filament::button
href="/admin"
icon='heroicon-o-arrow-left-start-on-rectangle'
icon-position='before'
size='sm'
outlined
tag="a"
>
<div class='flex items-center space-x-2'> <!-- Use a flex container with space between items -->
<span>{{ __('Exit Settings') }}</span>
</div>
</x-filament::button>
<x-filament::button
href="/admin"
icon='heroicon-o-arrow-left-start-on-rectangle'
icon-position='before'
size='sm'
outlined
tag="a"
>
<div class='flex items-center space-x-2'> <!-- Use a flex container with space between items -->
<span>{{ __('Exit Settings') }}</span>
</div>
</x-filament::button>
WEBMAS
WEBMAS2mo ago
This doesn't solve the problem either. Using a hook violates the integrity of the menu. The element should remain a navigation element.
cvc
cvc2mo ago
read the render hooks you can do it in the nav element PanelsRenderHook::SIDEBAR_NAV_END - In the sidebar, before </nav>
WEBMAS
WEBMAS2mo ago
How do I specify PanelsRenderHook::SIDEBAR_NAV_END in the Settings Resource?
cvc
cvc2mo ago
you dont, you do it in the panel as a render hook
WEBMAS
WEBMAS2mo ago
But then the button will not become active. Navigation concept breaks down
cvc
cvc2mo ago
have you tried it? you can put logic to change the state when you are on the url
WEBMAS
WEBMAS2mo ago
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.
Blackpig
Blackpig2mo ago
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
WEBMAS
WEBMAS2mo ago
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.
cvc
cvc2mo ago
Sorry i have given you all the ideas I have, and as @Blackpig says...
cvc
cvc2mo ago
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()), ....
WEBMAS
WEBMAS2mo ago
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...
cvc
cvc2mo ago
ok last attempt for me - so on your clusters do you have protected static ?int $navigationSort = 1;
WEBMAS
WEBMAS2mo ago
Yes
cvc
cvc2mo ago
ok and on your settings resource?
WEBMAS
WEBMAS2mo ago
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.
WEBMAS
WEBMAS2mo ago
No description
WEBMAS
WEBMAS2mo ago
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?
WEBMAS
WEBMAS2mo ago
Here is a clear example of what is required.
No description
WEBMAS
WEBMAS2mo ago
Is there a solution to this problem?
LeandroFerreira
LeandroFerreira2mo ago
hum.. I think you can't..
WEBMAS
WEBMAS2mo ago
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.
awcodes
awcodes2mo ago
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.
LeandroFerreira
LeandroFerreira2mo ago
Thank you for this info ✌️
WEBMAS
WEBMAS2mo ago
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.