set $columnSpan dynamically?
Is there any way to set $columnSpan based on logic? I'd like a widget to have full span when another widget next to it gets hidden based on logic.
13 Replies
Usually every property has a corresponding method where you can define logic.
The only way the documentation shows how to set that variable is this way:
protected int | string | array $columnSpan = 'full';
Check what methods widget has, there should be something like getcolumnspan
I tried that, but it threw this: 'myWidget::getcolumnspan()' is not compatible with method 'Filament\Widgets\TableWidget::getColumnSpan()
ahh, just figured it out. I'm using TableWidget, not Widget. TableWidget doesn't have the getColumnSpan method, but Widget does.
I'm displaying a table in the widget, so that's why I used TableWidget and not just Widget. I'm assuming there's a reason why TableWidget doesn't have the same getColumnSpan method?
tablewidget should extend widget i believe
so same methods should work
you just need to return correct values
It has as it extends the widget. You overwrote the widget method with a different signature.
I'm trying this, where am I going wrong?
protected function getColumnSpan(): int | array
{
$manager = app('impersonate');
if ($manager->isImpersonating()) {
return 2;
} else {
return 1;
}
}
wrong return type
and use markdown for code
I'm trying to set the columnspan, I think this just gets the value.
The method should be called during render
That did the job, thanks! Here's what I'm using, not sure what you meant by use markdown for code:
public function getColumnSpan(): int | string | array
{
$manager = app('impersonate');
if ($manager->isImpersonating()) {
$this->columnSpan = 1;
} else {
$this->columnSpan = 'full';
}
return $this->columnSpan;
}
public function render(): View
{
$this->getColumnSpan();
return view('filament.resources.overview');
}
I thought this should be called automatically but maybe I am wrong.
Regarding markdown please read #✅┊rules
Sorry, I jumped in without reading the rules. I'm on it, thanks.