mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-24 15:42:09 +08:00
[4.x] Fix all-table summaries (#19592)
* Fix all-table summaries * Avoid table wrapper if no page or all table summary --------- Co-authored-by: Dan Harrin <git@danharrin.com>
This commit is contained in:
co-authored by
Dan Harrin
parent
c9b6ecd0fb
commit
7d3d3165d3
@@ -45,7 +45,8 @@
|
||||
$hasColumnsLayout = $hasColumnsLayout();
|
||||
$hasPageSummary = $hasPageSummary();
|
||||
$hasAllTableSummary = $hasAllTableSummary();
|
||||
$hasSummary = ($hasPageSummary || $hasAllTableSummary) && $hasSummary($this->getAllTableSummaryQuery());
|
||||
$hasSummary = $hasSummary($this->getAllTableSummaryQuery());
|
||||
$hasTopLevelSummary = $hasSummary && ($hasPageSummary || $hasAllTableSummary);
|
||||
$header = $getHeader();
|
||||
$headerActions = array_filter(
|
||||
$getHeaderActions(),
|
||||
@@ -1330,7 +1331,7 @@
|
||||
}}
|
||||
@endif
|
||||
|
||||
@if ($hasSummary && (! $isReordering))
|
||||
@if ($hasTopLevelSummary && (! $isReordering))
|
||||
<table class="fi-ta-table">
|
||||
<tbody>
|
||||
<x-filament-tables::summary
|
||||
|
||||
@@ -1,8 +1,17 @@
|
||||
<?php
|
||||
|
||||
use Filament\Actions\Concerns\InteractsWithActions;
|
||||
use Filament\Actions\Contracts\HasActions;
|
||||
use Filament\Schemas\Concerns\InteractsWithSchemas;
|
||||
use Filament\Schemas\Contracts\HasSchemas;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Tests\Fixtures\Livewire\PostsTable;
|
||||
use Filament\Tests\Fixtures\Models\Post;
|
||||
use Filament\Tests\Tables\TestCase;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Livewire\Component;
|
||||
|
||||
use function Filament\Tests\livewire;
|
||||
|
||||
@@ -151,3 +160,40 @@ it('can sum subset of values in a column on this pagination page', function ():
|
||||
->assertCanSeeTableRecords($posts->take(10))
|
||||
->assertTableColumnSummarySet('rating', 'published_sum', $posts->take(10)->where('is_published', true)->sum('rating'), isCurrentPaginationPageOnly: true);
|
||||
});
|
||||
|
||||
it('renders group summaries when page and all-table summaries are disabled', function (): void {
|
||||
Post::factory()->count(5)->create();
|
||||
|
||||
livewire(TestTableWithGroupSummariesOnly::class)
|
||||
->assertSeeHtml('fi-ta-summary-row')
|
||||
->assertDontSeeHtml('fi-ta-summary-header-row');
|
||||
});
|
||||
|
||||
class TestTableWithGroupSummariesOnly extends Component implements HasActions, HasSchemas, Tables\Contracts\HasTable
|
||||
{
|
||||
use InteractsWithActions;
|
||||
use InteractsWithSchemas;
|
||||
use Tables\Concerns\InteractsWithTable;
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->query(Post::query())
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('title'),
|
||||
Tables\Columns\TextColumn::make('rating')
|
||||
->summarize([
|
||||
Tables\Columns\Summarizers\Sum::make('sum'),
|
||||
]),
|
||||
])
|
||||
->defaultGroup(
|
||||
Tables\Grouping\Group::make('is_published'),
|
||||
)
|
||||
->summaries(pageCondition: false, allTableCondition: false);
|
||||
}
|
||||
|
||||
public function render(): View
|
||||
{
|
||||
return view('livewire.table');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user