seamlessly
seamlessly
FFilament
Created by seamlessly on 11/22/2024 in #❓┊help
TableWidget: Modal in View Actions empty data
You can now add your widget onto the dashboard with:
class Dashboard extends FilamentDashboard
{
public function getWidgets(): array
{
return [
UserTableWidget::class,
];
}
...
class Dashboard extends FilamentDashboard
{
public function getWidgets(): array
{
return [
UserTableWidget::class,
];
}
...
If you have done everything correctly, you should now see the User table (with actions that appear as modals) on the dashboard.
5 replies
FFilament
Created by seamlessly on 11/22/2024 in #❓┊help
TableWidget: Modal in View Actions empty data
Hopefully this helps someone - I was able to solve this by passing ->statePath('state'), this also requires that the Widget has this state defined as public, it will not work if not defined in the class. This is the GenericTableWidget
<?php

namespace App\Filament\Widgets;

use Filament\Forms\Form;
use Filament\Tables\Actions\DeleteAction;
use Filament\Tables\Actions\EditAction;
use Filament\Tables\Actions\ViewAction;
use Filament\Tables\Table;
use Filament\Widgets\TableWidget as BaseWidget;

class GenericTableWidget extends BaseWidget
{
public array $state;
protected static string $resourceClass;

public function table(Table $table): Table
{
$class = static::$resourceClass;
$form = fn(Form $form) => $class::form($form);

return $table
->heading($class::getNavigationLabel())
->query($class::getModel()::query())
->columns($class::getTableColumns())
->actions([
ViewAction::make()->form($form),
EditAction::make()->form($form),
DeleteAction::make(),
]);
}
}
<?php

namespace App\Filament\Widgets;

use Filament\Forms\Form;
use Filament\Tables\Actions\DeleteAction;
use Filament\Tables\Actions\EditAction;
use Filament\Tables\Actions\ViewAction;
use Filament\Tables\Table;
use Filament\Widgets\TableWidget as BaseWidget;

class GenericTableWidget extends BaseWidget
{
public array $state;
protected static string $resourceClass;

public function table(Table $table): Table
{
$class = static::$resourceClass;
$form = fn(Form $form) => $class::form($form);

return $table
->heading($class::getNavigationLabel())
->query($class::getModel()::query())
->columns($class::getTableColumns())
->actions([
ViewAction::make()->form($form),
EditAction::make()->form($form),
DeleteAction::make(),
]);
}
}
Now you can extend this class to show a specific resource such as Users:
<?php

namespace App\Filament\Widgets;

use App\Filament\Resources\UserResource;

class UserTableWidget extends GenericTableWidget
{
protected static string $resourceClass = UserResource::class;
}
<?php

namespace App\Filament\Widgets;

use App\Filament\Resources\UserResource;

class UserTableWidget extends GenericTableWidget
{
protected static string $resourceClass = UserResource::class;
}
Make sure that in your UserResource you have defined the static function getTableColumns:
public static function getTableColumns(): array
{
return [
Tables\Columns\TextColumn::make('name'),
Tables\Columns\TextColumn::make('email'),
Tables\Columns\TextColumn::make('role.name')->label('Role')
];
}
public static function getTableColumns(): array
{
return [
Tables\Columns\TextColumn::make('name'),
Tables\Columns\TextColumn::make('email'),
Tables\Columns\TextColumn::make('role.name')->label('Role')
];
}
5 replies