F
Filamentβ€’22h ago
mohdaftab

Stats widget above the table linked to the table data

Hello, I have added this DashboardTable widget in my Dashboard and added the filters to search. I am looking to add some stats at the top of the table from all the paginated results and those stats should be linked to the search filters used in the table. Please let me know how to do that? Thank you
No description
Solution:
use this in your table widget ```php public function updated(string $name, string $value) {...
Jump to solution
6 Replies
Illizian
Illizianβ€’22h ago
use Filament\Pages\Concerns\ExposesTableToWidgets;
use Filament\Resources\Pages\ListRecords;

class ListProducts extends ListRecords
{
use ExposesTableToWidgets;

// ...
}
use Filament\Pages\Concerns\ExposesTableToWidgets;
use Filament\Resources\Pages\ListRecords;

class ListProducts extends ListRecords
{
use ExposesTableToWidgets;

// ...
}
https://filamentphp.com/docs/3.x/panels/resources/widgets I've not tried this myself, but you can get the data like this, not sure if it'll contain filters etc though πŸ™
mohdaftab
mohdaftabOPβ€’22h ago
@Illizian I am using a --table widget on the Dashboard page, is this going to work with ExposesTableToWidgets please ? I guess InteractsWithPageTable will work if we are using a widget class. Thank you for pointing this out. I will try it
Illizian
Illizianβ€’21h ago
Sorry, I didn't spot the part about it being a dashboard. Good luck
mohdaftab
mohdaftabOPβ€’16h ago
Unfortunately, the stats widgets aren't working with the table widgets
Solution
LeandroFerreira
LeandroFerreiraβ€’9h ago
use this in your table widget
public function updated(string $name, string $value)
{
if (str($name)->contains('tableFilters')) {
$this->dispatch('refreshStatsWidget', value: $value);
}
}

public function resetTableFiltersForm(): void
{
parent::resetTableFiltersForm();
$this->dispatch('refreshStatsWidget');
}
public function updated(string $name, string $value)
{
if (str($name)->contains('tableFilters')) {
$this->dispatch('refreshStatsWidget', value: $value);
}
}

public function resetTableFiltersForm(): void
{
parent::resetTableFiltersForm();
$this->dispatch('refreshStatsWidget');
}
in your stats widgets you can do this
use Livewire\Attributes\On;
...

public $tableFilter = null;

#[On('refreshStatsWidget')]
public function refreshStatsWidget(?string $value = null): void
{
$this->tableFilter = $value;
}
use Livewire\Attributes\On;
...

public $tableFilter = null;

#[On('refreshStatsWidget')]
public function refreshStatsWidget(?string $value = null): void
{
$this->tableFilter = $value;
}
$this->tableFilter will contain the table filter value
mohdaftab
mohdaftabOPβ€’3h ago
Thank you so much @Leandro Ferreira , I have actually changed it to be a resource and it worked great except for some permission issues, which I have posted in the other thread.

Did you find this page helpful?