gflaminio3/filament-nested-grouping

Nested (multi-level) grouping for Filament Tables

Installs: 2

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/gflaminio3/filament-nested-grouping

1.0.0 2025-11-04 23:32 UTC

This package is auto-updated.

Last update: 2025-11-04 23:35:03 UTC


README

Latest Version on Packagist Total Downloads License

This package extends Filament Tables to provide nested (multi-level) grouping capabilities.

Installation

Install the package via Composer:

composer require gflaminio3/filament-nested-grouping

Register the plugin in your Filament PanelProvider:

// app/Providers/Filament/AdminPanelProvider.php

use gflaminio3\FilamentNestedGrouping\Plugins\NestedGroupingPlugin;

class AdminPanelProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            // ...
            ->plugins([
                NestedGroupingPlugin::make(),
            ]);
    }
}

Usage

Use the NestedGroup class instead of Filament's standard Group for multi-level grouping.

use Filament\Tables\Table;
use Filament\Tables\Columns\TextColumn;
use gflaminio3\FilamentNestedGrouping\Tables\Grouping\NestedGroup;

class ListProducts extends ListRecords
{
    public static function table(Table $table): Table
    {
        return $table
            ->columns([
                TextColumn::make('category.name'),
                TextColumn::make('sub_category.name'),
                TextColumn::make('name'),
                TextColumn::make('price')->money(),
            ])
            ->groups([
                NestedGroup::make('category.name')
                    ->title('Category / Sub Category') // Optional custom title for the main group
                    ->thenBy('sub_category.name')       // Group by sub-category
                    ->thenByDate('created_at', 'month'), // Group by creation date (monthly)
            ]);
    }
}
  • NestedGroup::make(string $column): Starts a new nested group.
  • ->thenBy(string $column): Adds an additional grouping level by column.
  • ->thenByDate(string $column, string $precision = 'day'): Adds an additional grouping level by a date column, specifying year, month, or day precision.
  • ->title(string $title): Sets a custom title for the main nested group.

How it Works

The package extends Filament's Group class, introducing a NestedGroup to handle multiple grouping levels. It generates a composite key for each nested group and modifies Eloquent queries to include the necessary GROUP BY and ORDER BY clauses across all levels, including relationships.

Contributing

Feel free to submit pull requests or report issues.

License

This project is licensed under the MIT License.