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
Dennis Koch
Dennis Koch2y ago
Usually every property has a corresponding method where you can define logic.
usmcgator
usmcgatorOP2y ago
The only way the documentation shows how to set that variable is this way: protected int | string | array $columnSpan = 'full';
krekas
krekas2y ago
Check what methods widget has, there should be something like getcolumnspan
usmcgator
usmcgatorOP2y ago
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?
krekas
krekas2y ago
tablewidget should extend widget i believe so same methods should work you just need to return correct values
Dennis Koch
Dennis Koch2y ago
It has as it extends the widget. You overwrote the widget method with a different signature.
usmcgator
usmcgatorOP2y ago
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; } }
krekas
krekas2y ago
wrong return type and use markdown for code
public function getColumnSpan(): int | string | array
{
return $this->columnSpan;
}
public function getColumnSpan(): int | string | array
{
return $this->columnSpan;
}
usmcgator
usmcgatorOP2y ago
I'm trying to set the columnspan, I think this just gets the value.
Dennis Koch
Dennis Koch2y ago
The method should be called during render
usmcgator
usmcgatorOP2y ago
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'); }
Dennis Koch
Dennis Koch2y ago
I thought this should be called automatically but maybe I am wrong. Regarding markdown please read #✅┊rules
usmcgator
usmcgatorOP2y ago
Sorry, I jumped in without reading the rules. I'm on it, thanks.
Want results from more Discord servers?
Add your server