Skip to content

Commit a974ee7

Browse files
authored
Merge pull request #9 from biscofil/master
Order direction can also be specified with a separate "order" parameter
2 parents 2b16b04 + 61edf85 commit a974ee7

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ Your request to the controller should have this data:
4444
}
4545
```
4646

47+
You can also specify the sorting order using the "order" attribute (required by https://mannyyang.github.io/vuetable-3/ ):
48+
```javascript
49+
{
50+
sort: '', // column_name
51+
order: '', // asc or desc
52+
}
53+
```
54+
55+
4756
So for example lets create the table for the users with their companies. Then in the javascript we should have:
4857

4958
```javascript

src/Builders/CollectionVuetableBuilder.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,16 @@ public function sort()
7474
return $this;
7575
}
7676

77-
list($field, $direction) = explode('|', $this->request->input('sort'));
77+
$sort_parts = explode('|', $this->request->input('sort'));
78+
79+
$field = $sort_parts[0];
80+
81+
$direction = count($sort_parts) > 1
82+
? $sort_parts[1]
83+
: $this->request->input('order', 'desc');
7884

7985
if ($field) {
80-
$comparer = function ($a, $b) use ($field,$direction) {
86+
$comparer = function ($a, $b) use ($field, $direction) {
8187
if ($direction === 'desc') {
8288
$first = $b;
8389
$second = $a;

src/Builders/EloquentVuetableBuilder.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,15 @@ public function sort()
5959
if (!$this->request->input('sort')) {
6060
return $this;
6161
}
62+
63+
$sort_parts = explode('|', $this->request->input('sort'));
6264

63-
list($field, $direction) = explode('|', $this->request->input('sort'));
65+
$field = $sort_parts[0];
6466

67+
$direction = count($sort_parts) > 1
68+
? $sort_parts[1]
69+
: $this->request->input('order', 'desc');
70+
6571
$this->query->orderBy($field, $direction);
6672

6773
return $this;

0 commit comments

Comments
 (0)