Skip to content

Commit bcdf185

Browse files
authored
Merge pull request #363 from rappasoft/develop
v1.10.3
2 parents 2a32b6e + e5952de commit bcdf185

File tree

2 files changed

+71
-3
lines changed

2 files changed

+71
-3
lines changed

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ All notable changes to `laravel-livewire-tables` will be documented in this file
44

55
## [Unreleased]
66

7+
## [1.10.3] - 2021-06-22
8+
9+
### Added
10+
11+
- When reordering, the last known state of the table is now saved in the session so when you're done reordering you are back where you left off and no filters/sorts/search is lost.
12+
13+
### Changed
14+
15+
- Fixed query string getting wiped out on reload
16+
717
## [1.10.2] - 2021-06-21
818

919
### Changed
@@ -398,7 +408,8 @@ All notable changes to `laravel-livewire-tables` will be documented in this file
398408

399409
- Initial release
400410

401-
[Unreleased]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.10.2...development
411+
[Unreleased]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.10.3...development
412+
[1.10.3]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.10.2...v1.10.3
402413
[1.10.2]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.10.1...v1.10.2
403414
[1.10.1]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.10.0...v1.10.1
404415
[1.10.0]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.9.0...v1.10.0

src/Traits/WithReordering.php

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ public function mountWithReordering(): void
1616
if (! $this->reorderEnabled && $this->hasReorderingSession()) {
1717
$this->forgetReorderingSession();
1818
}
19-
20-
$this->setReorderingProperties();
2119
}
2220

2321
public function enableReordering(): void
@@ -51,6 +49,9 @@ private function setReorderingProperties(): void
5149
{
5250
if ($this->hasReorderingSession()) {
5351
$this->reordering = true;
52+
53+
$this->setReorderingBackup();
54+
5455
$this->bulkActionsEnabled = false;
5556
$this->selectPage = false;
5657
$this->selectAll = false;
@@ -68,6 +69,7 @@ private function setReorderingProperties(): void
6869
$this->resetPage();
6970
} else {
7071
$this->reordering = false;
72+
7173
$this->reset([
7274
'bulkActionsEnabled',
7375
'selectPage',
@@ -84,11 +86,66 @@ private function setReorderingProperties(): void
8486
'perPageAll',
8587
'perPage',
8688
]);
89+
90+
$this->getReorderingBackup();
8791
}
8892
}
8993

9094
private function getReorderingSessionKey(): string
9195
{
9296
return $this->tableName.'-reordering';
9397
}
98+
99+
private function getReorderingBackupSessionKey(): string
100+
{
101+
return $this->tableName.'-reordering-backup';
102+
}
103+
104+
private function setReorderingBackup(): void
105+
{
106+
if (session()->has($this->getReorderingBackupSessionKey())) {
107+
session()->forget($this->getReorderingBackupSessionKey());
108+
}
109+
110+
session([$this->getReorderingBackupSessionKey() => [
111+
'bulkActionsEnabled' => $this->bulkActionsEnabled,
112+
'selectPage' => $this->selectPage,
113+
'selectAll' => $this->selectAll,
114+
'selected' => $this->selected,
115+
'showSorting' => $this->showSorting,
116+
'sortingEnabled' => $this->sortingEnabled,
117+
'filtersEnabled' => $this->filtersEnabled,
118+
'sorts' => $this->sorts,
119+
'filters' => $this->filters,
120+
'showPagination' => $this->showPagination,
121+
'showPerPage' => $this->showPerPage,
122+
'showSearch' => $this->showSearch,
123+
'perPageAll' => $this->perPageAll,
124+
'perPage' => $this->perPage,
125+
'page' => $this->page,
126+
]]);
127+
}
128+
129+
private function getReorderingBackup(): void
130+
{
131+
if (session()->has($this->getReorderingBackupSessionKey())) {
132+
$save = session()->get($this->getReorderingBackupSessionKey());
133+
$this->bulkActionsEnabled = $save['bulkActionsEnabled'] ?? false;
134+
$this->selectPage = $save['selectPage'] ?? false;
135+
$this->selectAll = $save['selectAll'] ?? false;
136+
$this->selected = $save['selected'] ?? [];
137+
$this->showSorting = $save['showSorting'] ?? false;
138+
$this->sortingEnabled = $save['sortingEnabled'] ?? false;
139+
$this->filtersEnabled = $save['filtersEnabled'] ?? false;
140+
$this->sorts = $save['sorts'] ?? [];
141+
$this->filters = $save['filters'] ?? [];
142+
$this->showPagination = $save['showPagination'] ?? false;
143+
$this->showPerPage = $save['showPerPage'] ?? false;
144+
$this->showSearch = $save['showSearch'] ?? false;
145+
$this->perPageAll = $save['perPageAll'] ?? true;
146+
$this->perPage = $save['perPage'] ?? -1;
147+
$this->page = $save['page'] ?? 1;
148+
session()->forget($this->getReorderingBackupSessionKey());
149+
}
150+
}
94151
}

0 commit comments

Comments
 (0)