Skip to content

Commit d111841

Browse files
Merge pull request #68 from ACT-Training/67-set-scroll-position
67 set scroll position
2 parents d0f9d4e + 66d3866 commit d111841

6 files changed

Lines changed: 51 additions & 10 deletions

File tree

resources/views/report.blade.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
@if($this->rows->count())
4747

48-
<div class="relative overflow-x-auto">
48+
<div id="{{ $this->identifier() }}" class="relative overflow-x-auto">
4949
<table class="w-full text-sm text-left text-gray-500">
5050
<thead class="text-xs text-gray-700 uppercase bg-gray-50">
5151
<tr class="border-y border-gray-200">
@@ -166,7 +166,11 @@ class="sr-only ml-2 text-sm font-medium text-gray-900 dark:text-gray-300"></labe
166166

167167
@if($this->isPaginated() && $this->rows->hasPages())
168168
<div class="border-b border-gray-200 shadow-sm">
169-
<div class="py-2 px-6">{{ $this->rows->links(data: ['scrollTo' => $this->shouldScroll()]) }}</div>
169+
@if($this->scroll() === true)
170+
<div class="py-2 px-6">{{ $this->rows->links() }}</div>
171+
@else
172+
<div class="py-2 px-6">{{ $this->rows->links(data: ['scrollTo' => $this->scroll()]) }}</div>
173+
@endif
170174
</div>
171175
@endif
172176
@endif

resources/views/table.blade.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
@endif
2222
</div>
2323

24-
<div>
24+
<div id="{{ $this->identifier() }}">
2525
@if($this->rows->count())
2626
<div class="relative overflow-x-auto overflow-y-auto">
27-
<table class="w-full text-sm text-left text-gray-500" wire:key="table-1">
27+
<table class="w-full text-sm text-left text-gray-500" wire:key="{{ $this->identifier() }}">
2828
<thead class="text-xs text-gray-700 uppercase bg-gray-50">
2929
<tr class="border-y border-gray-200">
3030

@@ -110,7 +110,11 @@
110110
<div>
111111
@if($this->isPaginated() && $this->rows->hasPages())
112112
<div class="border-b border-gray-200 shadow-sm">
113-
<div class="py-2 px-6">{{ $this->rows->links(data: ['scrollTo' => $this->shouldScroll()]) }}</div>
113+
@if($this->scroll() === true)
114+
<div class="py-2 px-6">{{ $this->rows->links() }}</div>
115+
@else
116+
<div class="py-2 px-6">{{ $this->rows->links(data: ['scrollTo' => $this->scroll()]) }}</div>
117+
@endif
114118
</div>
115119
@endif
116120
</div>

src/QueryBuilder.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use ACTTraining\QueryBuilder\Support\Concerns\WithCaching;
1010
use ACTTraining\QueryBuilder\Support\Concerns\WithColumns;
1111
use ACTTraining\QueryBuilder\Support\Concerns\WithFilters;
12+
use ACTTraining\QueryBuilder\Support\Concerns\WithIdentifier;
1213
use ACTTraining\QueryBuilder\Support\Concerns\WithIndicator;
1314
use ACTTraining\QueryBuilder\Support\Concerns\WithPagination;
1415
use ACTTraining\QueryBuilder\Support\Concerns\WithQueryBuilder;
@@ -28,10 +29,12 @@
2829

2930
abstract class QueryBuilder extends Component
3031
{
32+
3133
use WithActions;
3234
use WithCaching;
3335
use WithColumns;
3436
use WithFilters;
37+
use WithIdentifier;
3538
use WithIndicator;
3639
use WithPagination;
3740
use WithQueryBuilder;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace ACTTraining\QueryBuilder\Support\Concerns;
4+
5+
use ACTTraining\QueryBuilder\Support\Actions\BaseAction;
6+
use Illuminate\Support\Enumerable;
7+
8+
trait WithIdentifier
9+
{
10+
protected string $identifier = 'table-builder';
11+
12+
public function identifier(): string
13+
{
14+
return $this->identifier;
15+
}
16+
17+
public function setIdentifier(string $identifier = 'table-builder'): static
18+
{
19+
$this->identifier = $identifier;
20+
21+
return $this;
22+
}
23+
24+
}

src/Support/Concerns/WithPagination.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ trait WithPagination
1212

1313
private bool $paginate = true;
1414

15-
private bool $scrollToTop = false;
15+
private bool|string $scrollTo = false; //false disables scroll on pagination
1616

1717
public function usePagination($usePagination = true): static
1818
{
@@ -21,16 +21,20 @@ public function usePagination($usePagination = true): static
2121
return $this;
2222
}
2323

24-
public function scrollToTop($scrollToTop = true): static
24+
public function shouldScrollTo($scrollTo): static
2525
{
26-
$this->scrollToTop = $scrollToTop;
26+
$this->scrollTo = match ($scrollTo) {
27+
'top' => true,
28+
'none' => false,
29+
default => $scrollTo,
30+
};
2731

2832
return $this;
2933
}
3034

31-
public function shouldScroll(): bool
35+
public function scroll(): bool|string
3236
{
33-
return $this->scrollToTop;
37+
return $this->scrollTo;
3438
}
3539

3640
public function pageName($pageName = null): static

src/TableBuilder.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use ACTTraining\QueryBuilder\Support\Concerns\WithColumns;
88
use ACTTraining\QueryBuilder\Support\Concerns\WithFilters;
9+
use ACTTraining\QueryBuilder\Support\Concerns\WithIdentifier;
910
use ACTTraining\QueryBuilder\Support\Concerns\WithIndicator;
1011
use ACTTraining\QueryBuilder\Support\Concerns\WithMessage;
1112
use ACTTraining\QueryBuilder\Support\Concerns\WithPagination;
@@ -27,6 +28,7 @@ abstract class TableBuilder extends Component
2728
{
2829
use WithColumns;
2930
use WithFilters;
31+
use WithIdentifier;
3032
use WithIndicator;
3133
use WithMessage;
3234
use WithPagination;

0 commit comments

Comments
 (0)