F
Filament8mo 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
WEBMASOP8mo 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
samran20008mo 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
WEBMASOP8mo ago
Groups do not have $navigationSort. Only elements within a group have this.
WEBMAS
WEBMASOP8mo ago
The Settings element is not a group. It is in the null group along with the Dashboard element.
samran2000
samran20008mo 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
WEBMASOP8mo 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.
nostrodamned
nostrodamned8mo 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
WEBMASOP8mo 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.
nostrodamned
nostrodamned8mo 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
WEBMASOP8mo 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.
nostrodamned
nostrodamned8mo 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
WEBMASOP8mo ago
This doesn't solve the problem either. Using a hook violates the integrity of the menu. The element should remain a navigation element.
nostrodamned
nostrodamned8mo ago
read the render hooks you can do it in the nav element PanelsRenderHook::SIDEBAR_NAV_END - In the sidebar, before </nav>
WEBMAS
WEBMASOP8mo ago
How do I specify PanelsRenderHook::SIDEBAR_NAV_END in the Settings Resource?
nostrodamned
nostrodamned8mo ago
you dont, you do it in the panel as a render hook
WEBMAS
WEBMASOP8mo ago
But then the button will not become active. Navigation concept breaks down
nostrodamned
nostrodamned8mo ago
have you tried it? you can put logic to change the state when you are on the url
WEBMAS
WEBMASOP8mo 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
Blackpig8mo 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
WEBMASOP8mo 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.
nostrodamned
nostrodamned8mo ago
Sorry i have given you all the ideas I have, and as @Blackpig says...
nostrodamned
nostrodamned8mo 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
WEBMASOP8mo 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...
nostrodamned
nostrodamned8mo ago
ok last attempt for me - so on your clusters do you have protected static ?int $navigationSort = 1;
WEBMAS
WEBMASOP8mo ago
Yes
nostrodamned
nostrodamned8mo ago
ok and on your settings resource?
WEBMAS
WEBMASOP8mo 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
WEBMASOP8mo ago
No description
WEBMAS
WEBMASOP8mo 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
WEBMASOP8mo ago
Here is a clear example of what is required.
No description
WEBMAS
WEBMASOP8mo ago
Is there a solution to this problem?
LeandroFerreira
LeandroFerreira8mo ago
hum.. I think you can't..
WEBMAS
WEBMASOP8mo 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
awcodes8mo 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
LeandroFerreira8mo ago
Thank you for this info ✌️
WEBMAS
WEBMASOP8mo 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.
Want results from more Discord servers?
Add your server