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
image.png
Solution
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');
}


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;
}


$this->tableFilter will contain the table filter value
Was this page helpful?