MedicOneSystems / livewire-datatables

Advanced datatables using Laravel, Livewire, Tailwind CSS and Alpine JS
https://livewire-datatables.com/
MIT License
1.19k stars 259 forks source link

Fixed a bug with the storage key saving for hidden columns and per page #604

Open Nowocyn opened 8 months ago

Nowocyn commented 8 months ago

The storage key for the hidden columns was created with $this->sessionStorageKey() and $this->name but only loaded by using $this->sessionStorageKey(). The same problem appeared with per page. Old:

public function setSessionStoredHidden()
    {
       //...
        session()->put([$this->sessionStorageKey() . $this->name . '_hidden_columns' => $hidden]);
    }

public function initialiseHiddenColumns()
    {
     //...
        if (session()->has($this->sessionStorageKey() . '_hidden_columns')) {
            $this->columns = collect($this->columns)->map(function ($column, $index) {
                $column['hidden'] = in_array($index, session()->get($this->sessionStorageKey() . '_hidden_columns'));

                return $column;
            })->toArray();
        }
    }

Changed:

session()->put([$this->sessionStorageKey() . $this->name . '_hidden_columns' => $hidden]);

to

session()->put([$this->sessionStorageKey() . '_hidden_columns' => $hidden]);

Second change:

$this->perPage = session()->get($this->sessionStorageKey() . $this->name . '_perpage', $this->perPage);

to

$this->perPage = session()->get($this->sessionStorageKey() . '_perpage', $this->perPage);
arm092 commented 3 months ago

Hey bro I've fixed this in my fork, also added Laravel 11 support

https://github.com/arm092/livewire-datatables/releases/tag/2.1.0