Skip to content

Commit e98df92

Browse files
committed
fix(request): sorting columns
1 parent 75097b2 commit e98df92

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

src/VueTableRequest.php

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ class VueTableRequest
3939
*/
4040
protected $search;
4141

42-
/**
43-
* @var array
44-
*/
45-
protected $sorting;
46-
4742
/**
4843
* VueTableRequest constructor.
4944
*
@@ -77,7 +72,6 @@ public function runQuery()
7772
$this->filters = $this->request->get('filters') ?? [];
7873
$this->perPage = $this->request->get('perPage') ?? 15;
7974
$this->search = $this->request->get('search') ?? '';
80-
$this->sorting = $this->request->get('sorting') ?? [];
8175

8276
$this->filterColumns();
8377
$this->sortColumns();
@@ -169,16 +163,16 @@ protected function applyFilter(Builder $query, array $modifiers, string $attribu
169163
*/
170164
private function sortColumns()
171165
{
172-
foreach ($this->sorting as $sort) {
173-
if (!isset($sort['column']) || !isset($sort['direction'])) {
174-
continue;
175-
}
166+
$sortTypes = ['asc', 'desc'];
176167

177-
if (!in_array($sort['direction'], ['asc', 'desc'])) {
178-
continue;
179-
}
168+
foreach ($this->columns as $name => $settings) {
169+
if (isset($settings['sort'])) {
170+
$sort = strtolower($settings['sort']);
180171

181-
$this->query->orderBy($sort['column'], $sort['direction']);
172+
if (in_array($sort, $sortTypes)) {
173+
$this->query->orderBy($name, $sort);
174+
}
175+
}
182176
}
183177
}
184178

0 commit comments

Comments
 (0)