Skip to content

Commit 79e05a8

Browse files
Merge pull request #66 from ACT-Training/65-prevent-scroll-on-pagination
✨ add scroll option
2 parents b3fa4c4 + 3f9d592 commit 79e05a8

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

resources/views/report.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ 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() }}</div>
169+
<div class="py-2 px-6">{{ $this->rows->links(['scrollTo' => $this->shouldScroll()]) }}</div>
170170
</div>
171171
@endif
172172
@endif

resources/views/table.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
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() }}</div>
113+
<div class="py-2 px-6">{{ $this->rows->links(['scrollTo' => $this->shouldScroll()]) }}</div>
114114
</div>
115115
@endif
116116
</div>

src/Support/Concerns/WithPagination.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,27 @@ trait WithPagination
1212

1313
private bool $paginate = true;
1414

15+
private bool $scrollToTop = false;
16+
1517
public function usePagination($usePagination = true): static
1618
{
1719
$this->paginate = $usePagination;
1820

1921
return $this;
2022
}
2123

24+
public function scrollToTop($scrollToTop = true): static
25+
{
26+
$this->scrollToTop = $scrollToTop;
27+
28+
return $this;
29+
}
30+
31+
public function shouldScroll(): bool
32+
{
33+
return $this->scrollToTop;
34+
}
35+
2236
public function pageName($pageName = null): static
2337
{
2438
$this->pageName = $pageName;

0 commit comments

Comments
 (0)