Filter Dynamic
This example uses Dynamic Filter in combination with WireUI.
ID
|
Dish
|
Category
|
---|---|---|
|
|
JSON.parse(atob('W10='))
|
1
|
Arkansas Possum Pie
|
Pasta
|
2
|
Albacore Tuna Melt
|
Soup
|
3
|
борщ
|
Soup
|
4
|
Bacalhau com natas
|
Fish
|
5
|
Baba Ghanoush
|
Meat
|
6
|
Bacon Cheeseburger
|
Fish
|
7
|
Baked potato
|
Fish
|
8
|
Baklava
|
Garnish
|
9
|
Bangers and mash
|
Meat
|
10
|
Black Pudding
|
Meat
|
Disclaimer: Table data is randomly generated for
illustrative purposes only. The information here is not a reflection of the actual market and does
not constitute business, financial, or medical advice.
<?php namespace App\Livewire\Examples\FilterDynamicTable; use App\Models\Dish;use Illuminate\Database\Eloquent\Builder;use PowerComponents\LivewirePowerGrid\Column;use PowerComponents\LivewirePowerGrid\Facades\Filter;use PowerComponents\LivewirePowerGrid\Footer;use PowerComponents\LivewirePowerGrid\PowerGrid;use PowerComponents\LivewirePowerGrid\PowerGridComponent;use PowerComponents\LivewirePowerGrid\PowerGridFields; class FilterDynamicTable extends PowerGridComponent{ public function setUp(): array { return [ Footer::make() ->showPerPage() ->showRecordCount(), ]; } public function datasource(): Builder { return Dish::with(['category', 'kitchen']); } public function relationSearch(): array { return [ 'category' => [ 'name', ], ]; } public function fields(): PowerGridFields { return PowerGrid::fields() ->add('id') ->add('name') ->add('category_id', fn ($dish) => intval($dish->category_id)) ->add('category_name', fn ($dish) => e($dish->category->name)); } public function columns(): array { return [ Column::make('ID', 'id') ->searchable() ->sortable(), Column::make('Dish', 'name') ->searchable() ->sortable(), Column::make('Category', 'category_name'), ]; } public function filters(): array { return [ Filter::dynamic('category_name', 'category_id') ->component('select') ->attributes([ 'async-data' => route('category.index'), 'option-label' => 'name', 'multiselect' => false, 'option-value' => 'id', 'wire:model.blur' => 'filters.select.category_id', 'placeholder' => 'Select a category', ]), ]; }}
Code highlighting provided by Torchlight.dev
Here you can find all relevant packages installed on this demo.
Name
|
Version
|
Description
|
---|---|---|
laravel/framework
|
v11
|
The Laravel Framework.
|
livewire/livewire
|
v3.5.0
|
A front-end framework for Laravel.
|
openspout/openspout
|
v4.24.1
|
PHP Library to read and write spreadsheet files (CSV, XLSX and ODS), in a fast and scalable way
|
power-components/livewire-powergrid
|
5.x-dev
|
PowerGrid generates Advanced Datatables using Laravel Livewire.
|
wireui/wireui
|
v1.19.1
|
TallStack components
|