Skip to content

Commit

Permalink
Move sorts to LW3 Approach
Browse files Browse the repository at this point in the history
  • Loading branch information
lrljoe committed Jul 20, 2023
1 parent bbb6be4 commit d7ccabf
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
1 change: 0 additions & 1 deletion src/DataTableComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ protected function generateDataTableFingerprint(): string
public function boot(): void
{
$this->{$this->tableName} = [
'sorts' => $this->{$this->tableName}['sorts'] ?? [],
'filters' => $this->{$this->tableName}['filters'] ?? [],
'columns' => $this->{$this->tableName}['columns'] ?? [],
];
Expand Down
12 changes: 6 additions & 6 deletions src/Traits/Helpers/SortingHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function getSingleSortingStatus(): bool
*/
public function getSorts(): array
{
return $this->{$this->getTableName()}['sorts'] ?? [];
return $this->sorts ?? [];
}

/**
Expand All @@ -28,17 +28,17 @@ public function getSorts(): array
*/
public function setSorts(array $sorts): array
{
return $this->{$this->getTableName()}['sorts'] = $sorts;
return $this->sorts = $sorts;
}

public function getSort(string $field): ?string
{
return $this->{$this->getTableName()}['sorts'][$field] ?? null;
return $this->sorts[$field] ?? null;
}

public function setSort(string $field, string $direction): string
{
return $this->{$this->getTableName()}['sorts'][$field] = $direction;
return $this->sorts[$field] = $direction;
}

public function hasSorts(): bool
Expand All @@ -56,12 +56,12 @@ public function hasSort(string $field): bool
*/
public function clearSorts(): void
{
$this->{$this->getTableName()}['sorts'] = [];
$this->sorts = [];
}

public function clearSort(string $field): void
{
unset($this->{$this->getTableName()}['sorts'][$field]);
unset($this->sorts[$field]);
}

public function setSortAsc(string $field): string
Expand Down
2 changes: 2 additions & 0 deletions src/Traits/WithSorting.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Rappasoft\LaravelLivewireTables\Traits;

use Illuminate\Database\Eloquent\Builder;
use Livewire\Attributes\Url;
use Rappasoft\LaravelLivewireTables\Traits\Configuration\SortingConfiguration;
use Rappasoft\LaravelLivewireTables\Traits\Helpers\SortingHelpers;

Expand All @@ -11,6 +12,7 @@ trait WithSorting
use SortingConfiguration,
SortingHelpers;

#[Url(history: true, as: 'sorts')]
public array $sorts = [];

public bool $sortingStatus = true;
Expand Down

0 comments on commit d7ccabf

Please sign in to comment.