Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions resources/views/report.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

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

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

@if($this->isPaginated() && $this->rows->hasPages())
<div class="border-b border-gray-200 shadow-sm">
<div class="py-2 px-6">{{ $this->rows->links(data: ['scrollTo' => $this->shouldScroll()]) }}</div>
@if($this->scroll() === true)
<div class="py-2 px-6">{{ $this->rows->links() }}</div>
@else
<div class="py-2 px-6">{{ $this->rows->links(data: ['scrollTo' => $this->scroll()]) }}</div>
@endif
</div>
@endif
@endif
Expand Down
10 changes: 7 additions & 3 deletions resources/views/table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
@endif
</div>

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

Expand Down Expand Up @@ -110,7 +110,11 @@
<div>
@if($this->isPaginated() && $this->rows->hasPages())
<div class="border-b border-gray-200 shadow-sm">
<div class="py-2 px-6">{{ $this->rows->links(data: ['scrollTo' => $this->shouldScroll()]) }}</div>
@if($this->scroll() === true)
<div class="py-2 px-6">{{ $this->rows->links() }}</div>
@else
<div class="py-2 px-6">{{ $this->rows->links(data: ['scrollTo' => $this->scroll()]) }}</div>
@endif
</div>
@endif
</div>
Expand Down
3 changes: 3 additions & 0 deletions src/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use ACTTraining\QueryBuilder\Support\Concerns\WithCaching;
use ACTTraining\QueryBuilder\Support\Concerns\WithColumns;
use ACTTraining\QueryBuilder\Support\Concerns\WithFilters;
use ACTTraining\QueryBuilder\Support\Concerns\WithIdentifier;
use ACTTraining\QueryBuilder\Support\Concerns\WithIndicator;
use ACTTraining\QueryBuilder\Support\Concerns\WithPagination;
use ACTTraining\QueryBuilder\Support\Concerns\WithQueryBuilder;
Expand All @@ -28,10 +29,12 @@

abstract class QueryBuilder extends Component
{

use WithActions;
use WithCaching;
use WithColumns;
use WithFilters;
use WithIdentifier;
use WithIndicator;
use WithPagination;
use WithQueryBuilder;
Expand Down
24 changes: 24 additions & 0 deletions src/Support/Concerns/WithIdentifier.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace ACTTraining\QueryBuilder\Support\Concerns;

use ACTTraining\QueryBuilder\Support\Actions\BaseAction;
use Illuminate\Support\Enumerable;

trait WithIdentifier
{
protected string $identifier = 'table-builder';

public function identifier(): string
{
return $this->identifier;
}

public function setIdentifier(string $identifier = 'table-builder'): static
{
$this->identifier = $identifier;

return $this;
}

}
14 changes: 9 additions & 5 deletions src/Support/Concerns/WithPagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ trait WithPagination

private bool $paginate = true;

private bool $scrollToTop = false;
private bool|string $scrollTo = false; //false disables scroll on pagination

public function usePagination($usePagination = true): static
{
Expand All @@ -21,16 +21,20 @@ public function usePagination($usePagination = true): static
return $this;
}

public function scrollToTop($scrollToTop = true): static
public function shouldScrollTo($scrollTo): static
{
$this->scrollToTop = $scrollToTop;
$this->scrollTo = match ($scrollTo) {
'top' => true,
'none' => false,
default => $scrollTo,
};

return $this;
}

public function shouldScroll(): bool
public function scroll(): bool|string
{
return $this->scrollToTop;
return $this->scrollTo;
}

public function pageName($pageName = null): static
Expand Down
2 changes: 2 additions & 0 deletions src/TableBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use ACTTraining\QueryBuilder\Support\Concerns\WithColumns;
use ACTTraining\QueryBuilder\Support\Concerns\WithFilters;
use ACTTraining\QueryBuilder\Support\Concerns\WithIdentifier;
use ACTTraining\QueryBuilder\Support\Concerns\WithIndicator;
use ACTTraining\QueryBuilder\Support\Concerns\WithMessage;
use ACTTraining\QueryBuilder\Support\Concerns\WithPagination;
Expand All @@ -27,6 +28,7 @@ abstract class TableBuilder extends Component
{
use WithColumns;
use WithFilters;
use WithIdentifier;
use WithIndicator;
use WithMessage;
use WithPagination;
Expand Down