F
Filament8mo ago
Bartek

Is there a way to display empty table in TableWidget if specific property of parent model is false?

I have created TableWidget inside which I have Table with custom query that pulls data from some external model. I'm displaying this widget on view resource page in footer. What I'm trying to do is to display empty table based on state of resource model property on which I'm displaying widget. I have tried to add conditional to table query to simply set it to null but I get error that my widget needs to have a query(). Any help will be appreciated. Thanks
Solution:
Ok, I have done it: In order to have empty widget table when parent record is disabled I have overridden getTableRecords() method in table widget like this: ```php...
Jump to solution
1 Reply
Solution
Bartek
Bartek8mo ago
Ok, I have done it: In order to have empty widget table when parent record is disabled I have overridden getTableRecords() method in table widget like this:
public function getTableRecords(): Paginator|CursorPaginator|Collection
{
if ($this->record->enabled) {
return parent::getTableRecords();
}

return Collection::make();
}
public function getTableRecords(): Paginator|CursorPaginator|Collection
{
if ($this->record->enabled) {
return parent::getTableRecords();
}

return Collection::make();
}
Want results from more Discord servers?
Add your server