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
2 changes: 1 addition & 1 deletion resources/views/components/actions.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class="flex items-center gap-1 w-full first-of-type:rounded-t-md last-of-type:ro
</button>
@else
<button
:disabled="{{ ! count($selectedRows) }}"
:disabled="{{ $selectedRows && ! count($selectedRows) }}"
wire:click="executeAction('{{ $action->key() }}')"
wire:key="action-{{ $action->key() }}"
@click="close($refs.button)"
Expand Down
65 changes: 64 additions & 1 deletion resources/views/table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<div class="my-6">

@if($this->isSearchVisible() && $this->searchableColumnsSet())
@if($this->isSearchVisible() && $this->searchableColumnsSet() && ! $this->areActionsVisible())
@if($this->isFiltered() || $this->isSearchActive() || $this->rows->count() > 0)
<div class="p-4 flex items-center gap-2 w-full">
@include('query-builder::components.search')
Expand All @@ -21,13 +21,44 @@
@endif
</div>

@if($this->areActionsVisible())
<div class="p-4 flex items-center gap-2 justify-between bg-gray-50">

<div class="p-4 flex items-center gap-2">
@if($this->isSearchVisible())
@include('query-builder::components.search')
@endif
</div>

<div class="p-4 flex items-center gap-2">

@if($this->areActionsVisible())
@include('query-builder::components.actions')
@endif

</div>
</div>
@endif


<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="{{ $this->identifier() }}">
<thead class="text-xs text-gray-700 bg-gray-50">
<tr class="border-y border-gray-200">

@if($this->areActionsVisible() && $selectable)
<th class="p-0">
<div class="pl-6 flex items-center">
<input wire:model.live="selectPage" id="checkbox-select-page" type="checkbox"
class="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600">
<label for="checkbox-select-page"
class="sr-only ml-2 text-sm font-medium text-gray-900 dark:text-gray-300"></label>
</div>
</th>
@endif

@foreach ($this->columns() as $column)
@if(!$column->hidden())
<th @if ($column->isSortable()) wire:click="sort('{{ $column->key }}')" @endif>
Expand Down Expand Up @@ -72,6 +103,25 @@
</thead>
<tbody>

@if($this->areActionsVisible() && $selectable && $selectPage && $this->rows->count() < $this->rows->total())
<tr class="bg-gray-100" wire:key="row-message">
<td colspan="{{ count($displayColumns) + 1 }}" class="px-6 py-4">
@unless($selectAll)
<div>
<span>You have selected <span
class="font-bold">{{ count($selectedRows) }} {{ Str::of('row')->plural(count($selectedRows)) }}</span>. Do you want to select all {{ $this->rows->total() }}?</span>
<button wire:click="selectAll"
class="ml-2 text-blue-500 hover:text-blue-600">
Select all
</button>
</div>
@else
<span>You have selected all {{ $this->rows->total() }} {{ Str::of('row')->plural(count($selectedRows)) }}.</span>
@endif
</td>
</tr>
@endif

@foreach ($this->rows as $row)

@if($this->rowPreview($row))
Expand All @@ -88,6 +138,19 @@
'hover:bg-gray-50 cursor-pointer' => $this->isClickable(),
])>

@if($this->areActionsVisible() && $selectable)
<td class="p-0">
<div class="pl-6 flex items-center">
<input wire:model.live="selectedRows" id="checkbox-{{ $row->id }}"
type="checkbox"
value="{{ $row->id }}"
class="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600">
<label for="checkbox-{{ $row->id }}"
class="sr-only ml-2 text-sm font-medium text-gray-900 dark:text-gray-300"></label>
</div>
</td>
@endif

@foreach ($this->columns() as $column)
@if(!$column->hidden())
<td>
Expand Down
6 changes: 6 additions & 0 deletions src/TableBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace ACTTraining\QueryBuilder;

use ACTTraining\QueryBuilder\Support\Concerns\WithActions;
use ACTTraining\QueryBuilder\Support\Concerns\WithColumns;
use ACTTraining\QueryBuilder\Support\Concerns\WithFilters;
use ACTTraining\QueryBuilder\Support\Concerns\WithIdentifier;
Expand All @@ -13,6 +14,7 @@
use ACTTraining\QueryBuilder\Support\Concerns\WithRowClick;
use ACTTraining\QueryBuilder\Support\Concerns\WithRowInjection;
use ACTTraining\QueryBuilder\Support\Concerns\WithSearch;
use ACTTraining\QueryBuilder\Support\Concerns\WithSelecting;
use ACTTraining\QueryBuilder\Support\Concerns\WithSorting;
use ACTTraining\QueryBuilder\Support\Concerns\WithViews;
use Illuminate\Contracts\View\Factory;
Expand All @@ -27,6 +29,7 @@

abstract class TableBuilder extends Component
{
use WithActions;
use WithColumns;
use WithFilters;
use WithIdentifier;
Expand All @@ -36,11 +39,14 @@ abstract class TableBuilder extends Component
use WithRowClick;
use WithRowInjection;
use WithSearch;
use WithSelecting;
use WithSorting;
use WithViews;

protected string $model = Model::class;

public array $rowOptions = [10, 25, 50];

protected $listeners = [
'refreshTable' => '$refresh',
];
Expand Down