Skip to content

Commit 1d991b2

Browse files
authored
Ensure Default Sorting Is Shown in Pills (rappasoft#2138)
* Ensure Default Sorting Is Shown in Pills * Fix styling * Fix return type --------- Co-authored-by: lrljoe <[email protected]>
1 parent c67247b commit 1d991b2

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/Traits/Configuration/SortingConfiguration.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44

55
trait SortingConfiguration
66
{
7+
protected function setupDefaultSorting(): void
8+
{
9+
if ($this->sortingIsEnabled() && $this->hasDefaultSort() && ! $this->hasSorts()) {
10+
$this->setSort($this->getDefaultSortColumn(), $this->getDefaultSortDirection());
11+
}
12+
}
13+
714
public function setSortingStatus(bool $status): self
815
{
916
$this->sortingStatus = $status;

src/Traits/WithSorting.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ trait WithSorting
3232

3333
public string $defaultSortingLabelDesc = 'Z-A';
3434

35+
public function mountWithSorting(): void
36+
{
37+
$this->setupDefaultSorting();
38+
}
39+
3540
public function sortBy(string $columnSelectName): ?string
3641
{
3742

@@ -66,11 +71,7 @@ public function sortBy(string $columnSelectName): ?string
6671

6772
public function applySorting(): Builder
6873
{
69-
if ($this->hasDefaultSort() && ! $this->hasSorts()) {
70-
$this->setBuilder($this->getBuilder()->orderBy($this->getDefaultSortColumn(), $this->getDefaultSortDirection()));
7174

72-
return $this->getBuilder();
73-
}
7475
$allCols = $this->getColumns();
7576

7677
foreach ($this->getSorts() as $column => $direction) {

0 commit comments

Comments
 (0)