Files
laralog/app/Filament/Resources/Posts/Tables/PostsTable.php
T
ak e9a0a49fb7 revert: 表格筛选回退默认 Dropdown 布局(与搜索同区、紧凑)
Above 布局与工具栏搜索分成两个区域且占空间;回退 Filament 标准做法:筛选按钮在工具栏、与搜索框同一行,激活时带数量徽章。保留表格行紧凑 CSS
2026-08-12 18:02:20 +08:00

94 lines
3.2 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Filament\Resources\Posts\Tables;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteBulkAction;
use Filament\Actions\EditAction;
use Filament\Actions\ViewAction;
use Filament\Forms\Components\Select;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Filters\TernaryFilter;
use Filament\Tables\Table;
class PostsTable
{
public static function configure(Table $table): Table
{
return $table
->columns([
TextColumn::make('title')
->label('标题')
->searchable()
->limit(40)
->description(fn ($record) => $record->category?->name),
TextColumn::make('content_format')
->label('格式')
->badge()
->formatStateUsing(fn ($state) => $state === 'markdown' ? 'MD' : 'HTML')
->color(fn ($state) => $state === 'markdown' ? 'success' : 'gray'),
TextColumn::make('status')
->label('状态')
->badge()
->formatStateUsing(fn ($state) => match ($state) {
'published' => '已发布',
'draft' => '草稿',
'private' => '私密',
default => $state,
})
->color(fn ($state) => match ($state) {
'published' => 'success',
'draft' => 'warning',
default => 'gray',
}),
IconColumn::make('is_sticky')
->label('置顶')
->boolean(),
TextColumn::make('views')
->label('阅读')
->numeric()
->sortable(),
TextColumn::make('comment_count')
->label('评论')
->numeric()
->sortable(),
TextColumn::make('published_at')
->label('发布时间')
->dateTime('Y-m-d H:i')
->sortable(),
])
->filters([
SelectFilter::make('status')
->label('状态')
->options([
'published' => '已发布',
'draft' => '草稿',
'private' => '私密',
]),
SelectFilter::make('content_format')
->label('格式')
->options([
'markdown' => 'Markdown',
'html' => 'HTML',
]),
TernaryFilter::make('is_sticky')
->label('置顶'),
])
->recordActions([
ViewAction::make(),
EditAction::make(),
])
->toolbarActions([
BulkActionGroup::make([
DeleteBulkAction::make(),
]),
])
->defaultSort('published_at', 'desc');
}
}