PHP code example of zvizvi / filament-column-filters
1. Go to this page and download the library: Download zvizvi/filament-column-filters library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
zvizvi / filament-column-filters example snippets
use Zvizvi\FilamentColumnFilters\FilamentColumnFiltersPlugin;
public function panel(Panel $panel): Panel
{
return $panel->plugin(FilamentColumnFiltersPlugin::make());
}
use Filament\Tables\Columns\TextColumn;
use Zvizvi\FilamentColumnFilters\Filters\ColumnFilter;
public function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('user_name')
->label('User Name')
->columnFilter(ColumnFilter::search()),
TextColumn::make('created_at')
->label('Date')
->date()
->columnFilter(ColumnFilter::date()),
TextColumn::make('status')
->columnFilter(
ColumnFilter::select()
->options([
'open' => 'Open',
'closed' => 'Closed',
])
->multiple(),
),
]);
}
ColumnFilter::search()
->placeholder('Search Name') // optional, defaults to "Search {label}"
ColumnFilter::date()
->presets(['today', 'yesterday', 'this_week', 'last_7_days']) // optional, defaults to all presets
->weekStartsOn(0) // 0 = Sunday (default), 1 = Monday
ColumnFilter::select()
->options(['a' => 'Option A', 'b' => 'Option B']) // array or closure
->multiple() // default: true; pass false for single select
->searchable() // force the option search field on (or off with false)
->searchThreshold(8) // options count above which the search field shows automatically (default: 8)
TextColumn::make('amount')
->columnFilter(
ColumnFilter::range()
->step(0.01), // optional step for the number inputs
),
$table
->columns([
TextColumn::make('status')
->columnFilter(ColumnFilter::select()), // auto-syncs with the "status" filter below
])
->filters([
SelectFilter::make('status')
->options([...])
->multiple(),
]);