tinyman1199
tinyman1199
FFilament
Created by tinyman1199 on 7/24/2024 in #❓┊help
Get current table data for widget
Hi, I'm using a widget on a view page with a table and need the widget to access the current data in the table. I've followed the instructions here https://filamentphp.com/docs/3.x/panels/resources/widgets#accessing-page-table-data-in-the-widget and it works when the page first loads but when you filter or change page the widget still seems to be getting the old data. The widget view uses javascript which needs to rerun with the new data. I've got this bit of code in the blade file which I'm not sure is the best way to rerun the javascript but it works (the javascript is rerunning but recieving the old data): {{$this->js('loadData()');}} Then within the loadData function I have this javascript to get the new data: var all = {{ $this->all() }}; And this is the widget file
<?php
namespace App\Filament\Resources\MapResource\Widgets;
use App\Filament\Resources\MapResource\Pages\ListMaps;
use Filament\Widgets\Concerns\InteractsWithPageTable;
use Filament\Widgets\Widget;

class CustomerMap extends Widget
{
use InteractsWithPageTable;
protected function getTablePage(): string
{
return ListMaps::class;
}
protected static bool $isLazy = false;

public function all(){
return $this->getPageTableRecords()->toJson();
}
protected static string $view = 'filament.resources.map-resource.widgets.customer-map';
}
<?php
namespace App\Filament\Resources\MapResource\Widgets;
use App\Filament\Resources\MapResource\Pages\ListMaps;
use Filament\Widgets\Concerns\InteractsWithPageTable;
use Filament\Widgets\Widget;

class CustomerMap extends Widget
{
use InteractsWithPageTable;
protected function getTablePage(): string
{
return ListMaps::class;
}
protected static bool $isLazy = false;

public function all(){
return $this->getPageTableRecords()->toJson();
}
protected static string $view = 'filament.resources.map-resource.widgets.customer-map';
}
But every time its called the $this->getPageTableRecords()->toJson() seems to return the data of the original page you start on rather than the current page or filtered data
8 replies
FFilament
Created by tinyman1199 on 3/11/2024 in #❓┊help
Access record from Tab Widget
Hi, I am trying to access the current record within a widget which is another tab on the infolist. I've tried adding public ?Model $record = null; within the widget class but it just returns null. I also tried passing it through the widget properties but couldn't get that to work. I was previously doing it by getting the url and getting the record ID from that but due to refreshing the widget using livewire after an action is performed this no longer works as the refresh url is different, something along the lines of .../livewire/refresh Any help is appreciated. Thanks
2 replies