© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
2 replies
Baspa

Dynamically set the order for the widgets on each page

Is there a way to do so? Or is that not possible yet? I tried adding this method and then call it with the make method, but that didn't work:

Widget class:
    public static function setSort(?int $sort): self
    {
        self::$sort = $sort;

        return new static();
    }
    public static function setSort(?int $sort): self
    {
        self::$sort = $sort;

        return new static();
    }


Dashboard.php

protected function getHeaderWidgets(): array
    {
        return $this->page->widgets->filter(function ($widget) {
            return $widget->pivot->position === 'top' || $widget->pivot->position === null;
        })->map(function ($widget) {
            if (method_exists($widget->class, 'make')) {
                return $widget->class::setSort($widget->pivot->order)->make([
                    'width' => $widget->pivot->width,
                ]);
            }
            return null;
        })->filter()->toArray();
    }
protected function getHeaderWidgets(): array
    {
        return $this->page->widgets->filter(function ($widget) {
            return $widget->pivot->position === 'top' || $widget->pivot->position === null;
        })->map(function ($widget) {
            if (method_exists($widget->class, 'make')) {
                return $widget->class::setSort($widget->pivot->order)->make([
                    'width' => $widget->pivot->width,
                ]);
            }
            return null;
        })->filter()->toArray();
    }
Screenshot_2024-05-24_at_10.24.08.png
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Dynamically loaded Widgets do not refresh when changing filters on the page
FilamentFFilament / ❓┊help
3y ago
Footer Widgets on Resource Page
FilamentFFilament / ❓┊help
3y ago
Set description for CheckboxList dynamically
FilamentFFilament / ❓┊help
2y ago
Set the HelperText attribute dynamically
FilamentFFilament / ❓┊help
3y ago