Skip to content

Commit 44eee22

Browse files
committed
fix persist
1 parent ddb91bb commit 44eee22

File tree

1 file changed

+5
-28
lines changed

1 file changed

+5
-28
lines changed

src/Http/Livewire/LivewireDatatable.php

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -494,20 +494,6 @@ public function setSessionStoredFilters()
494494
]);
495495
}
496496

497-
public function sort($index)
498-
{
499-
if ($this->sort === (int) $index) {
500-
$this->direction = ! $this->direction;
501-
} else {
502-
$this->sort = (int) $index;
503-
}
504-
$this->page = 1;
505-
506-
if ($this->persistSort) {
507-
$this->setSessionStoredSort();
508-
}
509-
}
510-
511497
public function initialiseSort()
512498
{
513499
$this->sort = $this->defaultSort()
@@ -528,13 +514,10 @@ public function initialiseHiddenColumns()
528514
}
529515

530516
if (session()->has($this->sessionStorageKey() . $this->name . '_hidden_columns')) {
531-
foreach (session()->get($this->sessionStorageKey() . $this->name . '_hidden_columns') as $name) {
532-
foreach ($this->columns as $key => $column) {
533-
if ($column['name'] === $name) {
534-
$this->columns[$key]['hidden'] = 1;
535-
}
536-
}
537-
}
517+
$this->columns = collect($this->columns)->map(function ($column, $index) {
518+
$column['hidden'] = in_array($index, session()->get($this->sessionStorageKey() . $this->name . '_hidden_columns'));
519+
return $column;
520+
})->toArray();
538521
}
539522
}
540523

@@ -656,13 +639,7 @@ public function toggle($index)
656639
$this->columns[$index]['hidden'] = ! $this->columns[$index]['hidden'];
657640

658641
if ($this->persistHiddenColumns) {
659-
$hidden = [];
660-
661-
foreach ($this->columns as $column) {
662-
if ($column['hidden']) {
663-
$hidden[] = $column['name'];
664-
}
665-
}
642+
$hidden = collect($this->columns)->filter->hidden->keys()->toArray();
666643

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

0 commit comments

Comments
 (0)