F
Filament2mo ago
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();
}
No description
2 Replies
Baspa
Baspa2mo ago
When I dump the value of $sort in the construct method of the widget it shows me the correct sort, but it seems like it's not respected by Filament?
public function __construct()
{
dump('weather sort: ' . self::$sort, self::getSort());
}
public function __construct()
{
dump('weather sort: ' . self::$sort, self::getSort());
}
toeknee
toeknee2mo ago
Checkout the #invaders-xx-gridstack-dashboard