Skip to content

Commit

Permalink
Merge pull request #12826 from bensondevs/3.x
Browse files Browse the repository at this point in the history
Feat: Adding grouping direction hidden method for the table grouping
  • Loading branch information
danharrin authored May 20, 2024
2 parents 66f7a2b + 23c73f1 commit 3960a09
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 34 deletions.
15 changes: 15 additions & 0 deletions packages/tables/docs/08-grouping.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,18 @@ public function table(Table $table): Table
->groupingSettingsHidden();
}
```

### Hiding the grouping direction setting only

You can hide the grouping direction select interface using the `groupingDirectionSettingHidden()` method:

```php
use Filament\Tables\Table;

public function table(Table $table): Table
{
return $table
->defaultGroup('status');
->groupingDirectionSettingHidden();
}
```
71 changes: 37 additions & 34 deletions packages/tables/resources/views/components/groups.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@props([
'directionSetting' => false,
'dropdownOnDesktop' => false,
'groups',
'triggerAction',
Expand Down Expand Up @@ -71,23 +72,24 @@
</x-filament::input.wrapper>
</label>

<label x-cloak x-show="group" class="grid gap-y-2">
<span class="{{ $labelClasses }}">
{{ __('filament-tables::table.grouping.fields.direction.label') }}
</span>

<x-filament::input.wrapper>
<x-filament::input.select x-model="direction">
<option value="asc">
{{ __('filament-tables::table.grouping.fields.direction.options.asc') }}
</option>

<option value="desc">
{{ __('filament-tables::table.grouping.fields.direction.options.desc') }}
</option>
</x-filament::input.select>
</x-filament::input.wrapper>
</label>
@if (! $directionSetting)
<label x-cloak x-show="group" class="grid gap-y-2">
<span class="{{ $labelClasses }}">
{{ __('filament-tables::table.grouping.fields.direction.label') }}
</span>
<x-filament::input.wrapper>
<x-filament::input.select x-model="direction">
<option value="asc">
{{ __('filament-tables::table.grouping.fields.direction.options.asc') }}
</option>

<option value="desc">
{{ __('filament-tables::table.grouping.fields.direction.options.desc') }}
</option>
</x-filament::input.select>
</x-filament::input.wrapper>
</label>
@endif
</div>
</x-filament::dropdown>

Expand Down Expand Up @@ -116,23 +118,24 @@
</x-filament::input.wrapper>
</label>

<label x-cloak x-show="group">
<span class="sr-only">
{{ __('filament-tables::table.grouping.fields.direction.label') }}
</span>

<x-filament::input.wrapper>
<x-filament::input.select x-model="direction">
<option value="asc">
{{ __('filament-tables::table.grouping.fields.direction.options.asc') }}
</option>

<option value="desc">
{{ __('filament-tables::table.grouping.fields.direction.options.desc') }}
</option>
</x-filament::input.select>
</x-filament::input.wrapper>
</label>
@if (! $directionSetting)
<label x-cloak x-show="group">
<span class="sr-only">
{{ __('filament-tables::table.grouping.fields.direction.label') }}
</span>
<x-filament::input.wrapper>
<x-filament::input.select x-model="direction">
<option value="asc">
{{ __('filament-tables::table.grouping.fields.direction.options.asc') }}
</option>

<option value="desc">
{{ __('filament-tables::table.grouping.fields.direction.options.desc') }}
</option>
</x-filament::input.select>
</x-filament::input.wrapper>
</label>
@endif
</div>
@endif
</div>
2 changes: 2 additions & 0 deletions packages/tables/resources/views/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
$isReorderable = $isReorderable();
$isReordering = $isReordering();
$areGroupingSettingsVisible = (! $isReordering) && count($groups) && (! $areGroupingSettingsHidden());
$isGroupingDirectionSettingHidden = $isGroupingDirectionSettingHidden();
$isColumnSearchVisible = $isSearchableByColumn();
$isGlobalSearchVisible = $isSearchable();
$isSearchOnBlur = $isSearchOnBlur();
Expand Down Expand Up @@ -195,6 +196,7 @@ class="fi-ta-header-toolbar flex items-center justify-between gap-x-4 px-4 py-3

@if ($areGroupingSettingsVisible)
<x-filament-tables::groups
:direction-setting="$isGroupingDirectionSettingHidden"
:dropdown-on-desktop="$areGroupingSettingsInDropdownOnDesktop()"
:groups="$groups"
:trigger-action="$getGroupRecordsTriggerAction()"
Expand Down
14 changes: 14 additions & 0 deletions packages/tables/src/Table/Concerns/CanGroupRecords.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ trait CanGroupRecords

protected bool | Closure $areGroupingSettingsHidden = false;

protected bool | Closure $isGroupingDirectionSettingHidden = false;

protected ?Closure $modifyGroupRecordsTriggerActionUsing = null;

public function groupRecordsTriggerAction(?Closure $callback): static
Expand Down Expand Up @@ -56,6 +58,13 @@ public function groupingSettingsHidden(bool | Closure $condition = true): static
return $this;
}

public function groupingDirectionSettingHidden(bool | Closure $condition = true): static
{
$this->isGroupingDirectionSettingHidden = $condition;

return $this;
}

public function defaultGroup(string | Group | null $group): static
{
$this->defaultGroup = $group;
Expand Down Expand Up @@ -130,6 +139,11 @@ public function areGroupingSettingsHidden(): bool
return (bool) $this->evaluate($this->areGroupingSettingsHidden);
}

public function isGroupingDirectionSettingHidden(): bool
{
return (bool) $this->evaluate($this->isGroupingDirectionSettingHidden);
}

public function getDefaultGroup(): ?Group
{
if ($this->defaultGroup === null) {
Expand Down

0 comments on commit 3960a09

Please sign in to comment.