tinyman1199
tinyman1199
FFilament
Created by tinyman1199 on 7/24/2024 in #❓┊help
Get current table data for widget
Solution provided by Leandro Livewire Component:
<?php

namespace App\Livewire;

use App\Models\Map;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Concerns\InteractsWithTable;
use Filament\Tables\Contracts\HasTable;
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Table;
use Filament\Widgets\Concerns\CanPoll;
use Illuminate\Contracts\View\View;
use Livewire\Component;

class ShowMap extends Component implements HasForms, HasTable
{
use CanPoll;
use InteractsWithForms;
use InteractsWithTable;

public function updatedTableFilters(): void
{
$this->dispatch('update-records', data: $this->getTableRecords()->toJson());
}

public function table(Table $table): Table
{
return $table
->query(Map::query())
->columns([
TextColumn::make('name'),
TextColumn::make('rating')
->badge(),
])
->filters([
SelectFilter::make('rating')
->options([
'ACTIVE' => 'Active',
'INACTIVE' => 'Inactive',
'DORMANT' => 'Dormant',
]),

]);
}

public function render(): View
{
return view('livewire.show-map');
}
}
<?php

namespace App\Livewire;

use App\Models\Map;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Concerns\InteractsWithTable;
use Filament\Tables\Contracts\HasTable;
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Table;
use Filament\Widgets\Concerns\CanPoll;
use Illuminate\Contracts\View\View;
use Livewire\Component;

class ShowMap extends Component implements HasForms, HasTable
{
use CanPoll;
use InteractsWithForms;
use InteractsWithTable;

public function updatedTableFilters(): void
{
$this->dispatch('update-records', data: $this->getTableRecords()->toJson());
}

public function table(Table $table): Table
{
return $table
->query(Map::query())
->columns([
TextColumn::make('name'),
TextColumn::make('rating')
->badge(),
])
->filters([
SelectFilter::make('rating')
->options([
'ACTIVE' => 'Active',
'INACTIVE' => 'Inactive',
'DORMANT' => 'Dormant',
]),

]);
}

public function render(): View
{
return view('livewire.show-map');
}
}
Blade file:
<div
x-data="{ records: @js($this->getTableRecords()->toJson()), init() { console.log(this.records) } }"
x-init="$watch('records', value => console.log(value))"
@update-records.window="records = $event.detail.data">

<div>
{{ $this->table }}
</div>

</div>
<div
x-data="{ records: @js($this->getTableRecords()->toJson()), init() { console.log(this.records) } }"
x-init="$watch('records', value => console.log(value))"
@update-records.window="records = $event.detail.data">

<div>
{{ $this->table }}
</div>

</div>
8 replies
FFilament
Created by tinyman1199 on 7/24/2024 in #❓┊help
Get current table data for widget
I changed it from a widget to a livewire component to see if that would work
8 replies
FFilament
Created by tinyman1199 on 7/24/2024 in #❓┊help
Get current table data for widget
Tried a few different methods, current attempt is in this github repo: https://github.com/ohhdeer/TableIssue I've removed alot of the unnecessary code. On the map page (show-map.blade.php) its the data being console logged on line 16 that needs to update but it stays the same even when the table updates
8 replies
FFilament
Created by tinyman1199 on 7/24/2024 in #❓┊help
Get current table data for widget
bumping
8 replies