rappasoft / laravel-livewire-tables

A dynamic table component for Laravel Livewire
https://rappasoft.com/docs/laravel-livewire-tables/v2/introduction
MIT License
1.71k stars 320 forks source link

[Bug]: setFilter() has no effect #1440

Closed nathan-io closed 8 months ago

nathan-io commented 8 months ago

What happened?

We're passing an array $filters to the component from our view, then setting those filters like so:

    public function mount($filters = [])
    {
        foreach ($filters as $key => $value) {
            $this->setFilter($key, $value);
        }
    }

This works in v2, but in v3-beta4 the filters aren't applied when the table is loaded.

We can apply them manually via the filter UI, that works fine.

How to reproduce the bug

No response

Package Version

3.0.0-beta4

PHP Version

8.1.x

Laravel Version

10.x

Alpine Version

No response

Theme

Tailwind 3.x

Notes

No response

Error Message

No response

lrljoe commented 8 months ago

Thanks for raising the bug.

Just as a test, could you please try the following:

    public function mount($filters = [])
    {
        foreach ($filters as $key => $value) {
          $this->appliedFilters[$key ] = $this->filterComponents[$key ] = $value;
        }
    }
nathan-io commented 8 months ago

Thanks for the fast response! That fixes it.

lrljoe commented 8 months ago

Great, I'll update the setFilter() method to update both to save you having to update a ton of tables.

Expect that to be in beta.8 (tomorrow)

lrljoe commented 8 months ago

PR #1449 <- for reference

lrljoe commented 8 months ago

Fix should be in v3.0.0-beta.8, please re-open and let me know if something is broken!

nathan-io commented 8 months ago

Getting the same result with beta8. Tried both versions:

$this->setFilter($key, $value);
$this->appliedFilters[$key] = $this->filterComponents[$key] = $value; 

Also tried just removing that block.

It looks like beta9 is out, but for some reason composer update keeps beta8.

nathan-io commented 8 months ago

I got beta9 installed and that fixes it, sorry for any confusion. Everything is working perfectly using

$this->setFilter($key, $value);