Skip to content

Commit 474e42f

Browse files
[6.x] Respect configured sort column & direction on collection index (#12234)
1 parent cb12e54 commit 474e42f

3 files changed

Lines changed: 13 additions & 1 deletion

File tree

resources/js/components/collections/Listing.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,13 @@
6161
</ui-panel-header>
6262

6363
<ui-card class="h-40 px-0! py-2!">
64-
<ui-listing :url="collection.entries_listing_url" :per-page="5" :columns="collection.columns">
64+
<ui-listing
65+
:url="collection.entries_listing_url"
66+
:per-page="5"
67+
:columns="collection.columns"
68+
:sort-column="collection.sort_column"
69+
:sort-direction="collection.sort_direction"
70+
>
6571
<template #initializing>
6672
<div class="flex flex-col gap-[9px] justify-between py-1 px-5">
6773
<ui-skeleton class="h-[19px] w-full" />

src/Http/Controllers/CP/Collections/CollectionsController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ private function collections()
8484
'actions' => Action::for($collection),
8585
'actions_url' => cp_route('collections.actions.run'),
8686
'icon' => $collection->icon(),
87+
'sort_column' => $collection->sortField(),
88+
'sort_direction' => $collection->sortDirection(),
8789
];
8890
})->sortBy('title')->values();
8991
}

tests/Feature/Collections/ViewCollectionListingTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ public function it_shows_a_list_of_collections()
5858
'actions' => Facades\Action::for($collectionA, ['view' => 'list']),
5959
'actions_url' => 'http://localhost/cp/collections/actions',
6060
'icon' => 'collections',
61+
'sort_column' => 'title',
62+
'sort_direction' => 'asc',
6163
],
6264
[
6365
'id' => 'foo',
@@ -87,6 +89,8 @@ public function it_shows_a_list_of_collections()
8789
'actions' => Facades\Action::for($collectionB, ['view' => 'list']),
8890
'actions_url' => 'http://localhost/cp/collections/actions',
8991
'icon' => 'collections',
92+
'sort_column' => 'title',
93+
'sort_direction' => 'asc',
9094
],
9195
]))
9296
->assertDontSee('ui-empty-state-menu');

0 commit comments

Comments
 (0)