File tree Expand file tree Collapse file tree 1 file changed +6
-0
lines changed Expand file tree Collapse file tree 1 file changed +6
-0
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,8 @@ trait WithSorting
15
15
public array $ sorts = [];
16
16
public array $ sortNames = [];
17
17
public array $ sortDirectionNames = [];
18
+ public string $ defaultSortColumn = '' ;
19
+ public string $ defaultSortDirection = 'asc ' ;
18
20
19
21
public function sortBy (string $ field ): ?string
20
22
{
@@ -42,6 +44,10 @@ public function sortBy(string $field): ?string
42
44
*/
43
45
public function applySorting ($ query )
44
46
{
47
+ if (! empty ($ this ->defaultSortColumn ) && empty ($ this ->sorts )) {
48
+ return $ query ->orderBy ($ this ->defaultSortColumn , $ this ->defaultSortDirection );
49
+ }
50
+
45
51
foreach ($ this ->sorts as $ field => $ direction ) {
46
52
if (optional ($ this ->getColumn ($ field ))->hasSortCallback ()) {
47
53
$ query = app ()->call ($ this ->getColumn ($ field )->getSortCallback (), ['query ' => $ query , 'direction ' => $ direction ]);
You can’t perform that action at this time.
0 commit comments