-
Hello, I've been trying to debug for two days and I can't really figure out what the issue is so i'm trying my luck here. I had an older project on Laravel 8 that I've updated to Laravel 10. I've updated all the dependecies and of course I started changing my tables to match the newer version. The problem I'm having can be described with this short movie below. Basically, after changing a filter, it doesn't actually refresh the table. If you change the filter again, it refreshes but with the previously selected value. https://share.cleanshot.com/2XbtbHf7 My table is as follows: <?php
namespace App\Http\Livewire\Operator;
use App\Helpers\CurrencyHelper;
use App\Models\Currency;
use Illuminate\Database\Eloquent\Builder;
use Rappasoft\LaravelLivewireTables\DataTableComponent;
use Rappasoft\LaravelLivewireTables\Views\Column;
use Rappasoft\LaravelLivewireTables\Views\Filters\SelectFilter;
class CurrenciesTable extends DataTableComponent
{
protected $model = Currency::class;
public bool $dumpFilters = true;
public function configure(): void
{
$this->setPrimaryKey('id');
}
public function builder(): Builder
{
return Currency::query()
->select('id', 'currency', 'name', 'rate', 'inverse_rate', 'default', 'active')
->when($this->getAppliedFilterWithValue('defaultFilter'), fn ($query, $value) => $query->where('default', $value))
->when($this->getAppliedFilterWithValue('activeFilter'), fn ($query, $value) => $query->where('active', $value));
}
public function filters(): array
{
return [
SelectFilter::make('Default', 'defaultFilter')
->options([
'' => 'Any',
1 => 'Yes',
0 => 'No',
]),
SelectFilter::make('Active', 'activeFilter')
->options([
'' => 'Any',
1 => 'Yes',
0 => 'No',
])
];
}
public function columns(): array
{
return [
Column::make('Currency', 'currency')
->sortable()
->searchable(),
Column::make('Name', 'name')
->sortable()
->searchable(),
Column::make('Rate', 'rate')
->sortable()
->searchable(),
Column::make('Inverse rate', 'inverse_rate')
->sortable()
->searchable(),
Column::make('Default', 'default')
->sortable()
->format(function ($value, $row) {
if ($value) {
return '<div class="text-center"><i class="far fa-shield-check text-success"></i></div>';
}
return '<div class="text-center"><i class="fal fa-times-circle text-danger" wire:click="changeDefault('.$row->id.', '.$value.')"></i></div>';
})
->html(),
Column::make('Active', 'active')
->sortable()
->format(function ($value, $row) {
return '<div class="text-center">'.($value ? '<i class="far fa-shield-check text-success" wire:click="changeActive('.$row->id.', '.$value.')"></i>' : '<i class="fal fa-times-circle text-danger" wire:click="changeActive('.$row->id.', '.$value.')"></i>').'</div>';
})
->html(),
];
}
}
`
Steps I've taken to debug:
1. Updated livewire.
2. Updated alpine version
3. Updated bootstrap 5
4. Cleared all the cache and compiled views
5. Tried 2.12.0 version and 2.13.0 with same results.
6. Asked a colleague to try on their machine with the same results.
Package versions:
Livewire 2.12.3
laravel-livewire-tables 2.13.1
php 8.1 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Couple of quick pointers. You shouldn't call select() as the package will figure out the columns you need automagically based on your column names. Use setAdditionalSelects() if you need to add fields that don't have a direct column For applying filters, I find the smoothest way is "Apply Filters at the Filter Level", docs are here which explain it better than I would! |
Beta Was this translation helpful? Give feedback.
-
I suspect getAppliedFilterWithValue() to be not working properly in the component level. For me, it does not filter when I emit to 'setFilter' as expected. It does filter, but always lags 1 request behind (set filter > datatable is reloaded > nothing is filtered > remove filter > datatable is reloaded > datatable is filtered with the previous filter). I checked the source, and I can't see any piece of code in "WithData" and "WithFilter" that points in the direction that proves getAppliedFilterWithValue could work at all. $this->setBuilder($this->applyFilters()); is called in WithData on line 37, but for me, no filter callback method is defined on the filters level. In my case, I can't define the filter callback method on the filters level, because the query is rather complex (with joins to other tables). Am I missing something obvious? |
Beta Was this translation helpful? Give feedback.
Couple of quick pointers.
You shouldn't call select() as the package will figure out the columns you need automagically based on your column names.
Use setAdditionalSelects() if you need to add fields that don't have a direct column
For applying filters, I find the smoothest way is "Apply Filters at the Filter Level", docs are here which explain it better than I would!
https://rappasoft.com/docs/laravel-livewire-tables/v2/filters/applying-filters