Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix table groups only extra column #9362

Merged
merged 13 commits into from
Nov 15, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
'actionsPosition' => null,
'columns',
'extraHeadingColumn' => false,
'groupColumn' => null,
'groupsOnly' => false,
'placeholderColumns' => true,
'pluralModelLabel',
Expand All @@ -16,6 +17,9 @@
use Filament\Tables\Enums\ActionsPosition;
use Filament\Tables\Enums\RecordCheckboxPosition;

if ($groupsOnly && $groupColumn) {
$columns = collect($columns)->reject(fn ($column) => $column->getName() == $groupColumn)->toArray();
danharrin marked this conversation as resolved.
Show resolved Hide resolved
}
danharrin marked this conversation as resolved.
Show resolved Hide resolved
$hasPageSummary = (! $groupsOnly) && $records instanceof \Illuminate\Contracts\Pagination\Paginator && $records->hasPages();
@endphp

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
'actionsPosition' => null,
'columns',
'extraHeadingColumn' => false,
'groupColumn' => null,
'groupsOnly' => false,
'heading',
'placeholderColumns' => true,
Expand All @@ -16,6 +17,10 @@
use Filament\Support\Enums\Alignment;
use Filament\Tables\Enums\ActionsPosition;
use Filament\Tables\Enums\RecordCheckboxPosition;

if ($groupsOnly && $groupColumn) {
$columns = collect($columns)->reject(fn ($column) => $column->getName() == $groupColumn)->toArray();
danharrin marked this conversation as resolved.
Show resolved Hide resolved
}
@endphp

<x-filament-tables::row
Expand All @@ -34,7 +39,7 @@

@if ($extraHeadingColumn || $groupsOnly)
<x-filament-tables::cell
class="text-sm font-medium text-gray-950 dark:text-white"
class="px-3 text-sm font-medium text-gray-950 dark:text-white"
zepfietje marked this conversation as resolved.
Show resolved Hide resolved
>
{{ $heading }}
</x-filament-tables::cell>
Expand Down
31 changes: 18 additions & 13 deletions packages/tables/resources/views/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -700,23 +700,25 @@ class="mx-1 my-2 shrink-0"

@if ($isSelectionEnabled && $recordCheckboxPosition === RecordCheckboxPosition::BeforeCells)
<x-filament-tables::selection.cell tag="th">
<x-filament-tables::selection.checkbox
:label="__('filament-tables::table.fields.bulk_select_page.label')"
x-bind:checked="
const recordsOnPage = getRecordsOnPage()
@if (! $isGroupsOnly)
<x-filament-tables::selection.checkbox
:label="__('filament-tables::table.fields.bulk_select_page.label')"
x-bind:checked="
const recordsOnPage = getRecordsOnPage()

if (recordsOnPage.length && areRecordsSelected(recordsOnPage)) {
$el.checked = true
if (recordsOnPage.length && areRecordsSelected(recordsOnPage)) {
$el.checked = true

return 'checked'
}
return 'checked'
}

$el.checked = false
$el.checked = false

return null
"
x-on:click="toggleSelectRecordsOnPage"
/>
return null
"
x-on:click="toggleSelectRecordsOnPage"
/>
@endif
</x-filament-tables::selection.cell>
@endif

Expand Down Expand Up @@ -864,6 +866,7 @@ class="mx-1 my-2 shrink-0"
:actions="count($actions)"
:actions-position="$actionsPosition"
:columns="$columns"
:group-column="$group?->getColumn()"
:groups-only="$isGroupsOnly"
:heading="$isGroupsOnly ? $previousRecordGroupTitle : __('filament-tables::table.summary.subheadings.group', ['group' => $previousRecordGroupTitle, 'label' => $pluralModelLabel])"
:query="$group->scopeQuery($this->getAllTableSummaryQuery(), $previousRecord)"
Expand Down Expand Up @@ -1069,6 +1072,7 @@ class="fi-ta-record-checkbox"
:actions="count($actions)"
:actions-position="$actionsPosition"
:columns="$columns"
:group-column="$group?->getColumn()"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually need the ? here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should? line 857, 858 is using the ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, in most other places we don't. 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't think it matters much tbh

:groups-only="$isGroupsOnly"
:heading="$isGroupsOnly ? $previousRecordGroupTitle : __('filament-tables::table.summary.subheadings.group', ['group' => $previousRecordGroupTitle, 'label' => $pluralModelLabel])"
:query="$group->scopeQuery($this->getAllTableSummaryQuery(), $previousRecord)"
Expand All @@ -1083,6 +1087,7 @@ class="fi-ta-record-checkbox"
:actions="count($actions)"
:actions-position="$actionsPosition"
:columns="$columns"
:group-column="$group?->getColumn()"
:groups-only="$isGroupsOnly"
:plural-model-label="$pluralModelLabel"
:record-checkbox-position="$recordCheckboxPosition"
Expand Down