ymsoft/filament-table-presets

A Filament plugin to save and load table presets

Fund package maintenance!
ymsoft

Installs: 19

Dependents: 0

Suggesters: 0

Security: 0

Stars: 5

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/ymsoft/filament-table-presets

0.1.0 2025-10-25 10:28 UTC

This package is auto-updated.

Last update: 2025-11-25 17:23:43 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

A powerful Filament plugin that allows users to save, manage, and share table configurations including filters, sorting, search queries, and visible columns. Perfect for teams that need to maintain multiple views of their data.

Demo

Table of Contents

Features

  • πŸ’Ύ Save Table States - Preserve filters, sorting, search, and column visibility
  • πŸ‘₯ Public & Private Presets - Share presets with team members or keep them private
  • 🎯 Default Presets - Set default preset that applies automatically on page load
  • πŸ”„ Quick Switching - Toggle between presets with one click via table header actions
  • πŸ” Policy-Based Access Control - Full authorization support for preset management
  • πŸ”— Polymorphic User Relations - Support for multi-tenancy and different user types
  • ⚑ Auto-Reset Support - Optionally clear active preset on manual filter/sort changes
  • πŸŒ“ Theme Support - Full support for light and dark modes
  • 🌍 Translatable - Built-in support for multiple languages

Installation

Install the package via Composer:

composer require ymsoft/filament-table-presets

Use the installation command to publish and run migrations automatically:

php artisan filament-table-presets:install

Optionally, publish the config file:

php artisan vendor:publish --tag="filament-table-presets-config"

Optionally, publish the views:

php artisan vendor:publish --tag="filament-table-presets-views"

Configuration

Custom Theme Setup

To ensure proper styling, you need to use a custom theme and include the plugin's CSS:

Step 1: Make sure you have a custom theme configured in your Filament panel.

Step 2: Add the plugin's CSS import to your theme file (e.g., resources/css/filament/admin/theme.css):

@import '../../../../vendor/ymsoft/filament-table-presets/resources/css/styles.css';

Step 3: Recompile your theme:

npm run build

Note: Make sure the vendor folder for this plugin is published so that it includes the Tailwind CSS classes.

Panel Registration

Register the plugin in your Filament panel configuration:

use Ymsoft\FilamentTablePresets\FilamentTablePresetPlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        ->plugins([
            FilamentTablePresetPlugin::make(),
        ]);
}

Polymorphic User Relationships

If you need to support polymorphic user relationships (useful for multi-tenancy or multiple user types), you need to configure both the plugin and the migration.

Step 1: Enable polymorphic relationships in the plugin:

FilamentTablePresetPlugin::make()
    ->hasPolymorphicUserRelationship()

Step 2: Modify the published migration file to use morphs:

In database/migrations/create_filament_table_presets_table.php, uncomment the morph lines and comment out the regular foreign keys:

Schema::create('filament_table_presets', function (Blueprint $table) {
    $table->id();
    $table->string('resource_class');

    // Uncomment for polymorphic relationships:
    $table->morphs('owner');
    // Comment out the regular foreign key:
    // $table->foreignId('owner_id')->constrained('users')->cascadeOnDelete();

    // ... rest of the columns
});

Schema::create('filament_table_preset_user', function (Blueprint $table) {
    $table->foreignId('preset_id')->constrained('filament_table_presets')->cascadeOnDelete();

    // Uncomment for polymorphic relationships:
    $table->morphs('user');

    // Comment out the regular foreign key:
    // $table->foreignId('user_id')->constrained('users')->cascadeOnDelete();

    // ... rest of the columns
});

This allows presets to be associated with different user models (e.g., App\Models\User, App\Models\Admin, App\Models\Customer, etc.).

Custom Modal Table

The preset management modal uses a fully-featured Filament table with all the benefits and flexibility you'd expect. This means you can easily customize it to fit your needsβ€”add custom columns, filters, actions, bulk actions, or modify the layout as you would with any Filament table.

To customize the table displayed in the preset management modal, simply pass your custom table class:

FilamentTablePresetPlugin::make()
    ->modalTable(MyCustomTableClass::class)

The table leverages all of Filament's table capabilities, including sorting, searching, drag-and-drop reordering, and more. You have complete control over its appearance and behavior.

User Model Trait

Add the WithFilamentTablePresets trait to your User model:

use Illuminate\Foundation\Auth\User as Authenticatable;
use Ymsoft\FilamentTablePresets\Traits\WithFilamentTablePresets;

class User extends Authenticatable
{
    use WithFilamentTablePresets;

    // ...
}

Usage

Basic Setup

To enable table presets on a List page, implement the HasFilamentTablePresets interface and use the WithFilamentTablePresets trait:

use Filament\Resources\Pages\ListRecords;
use Ymsoft\FilamentTablePresets\Filament\Actions\ManageTablePresetAction;
use Ymsoft\FilamentTablePresets\Filament\Pages\HasFilamentTablePresets;
use Ymsoft\FilamentTablePresets\Filament\Pages\WithFilamentTablePresets;

class ListProducts extends ListRecords implements HasFilamentTablePresets
{
    use WithFilamentTablePresets;

    protected static string $resource = ProductResource::class;

    public function mount(): void
    {
        parent::mount();

        $this->applyDefaultPreset();
    }

    protected function getTableHeaderActions(): array
    {
        return $this->retrieveVisiblePresetActions();
    }

    protected function getHeaderActions(): array
    {
        return [
            CreateAction::make(),
            ManageTablePresetAction::make(),
        ];
    }
}

Auto-Reset Active Preset

If you want to automatically deselect the active preset when users manually change filters or sorting, override these methods:

protected function handleTableFilterUpdates(): void
{
    $this->selectedFilamentPreset = null;

    parent::handleTableFilterUpdates();
}

public function updatedTableSort(): void
{
    $this->selectedFilamentPreset = null;

    parent::updatedTableSort();
}

This ensures that when users manually adjust table settings, the preset indicator is cleared to avoid confusion.

Working with Presets

Apply Default Preset

public function mount(): void
{
    parent::mount();

    $this->applyDefaultPreset();
}

Retrieve Visible Preset Actions

Display preset quick-switch buttons in the table header:

protected function getTableHeaderActions(): array
{
    return $this->retrieveVisiblePresetActions();
}

Manage Presets Action

Add the preset management modal to your page header:

protected function getHeaderActions(): array
{
    return [
        ManageTablePresetAction::make(),
    ];
}

Preset Management

Users can manage their presets through the management modal, which provides:

  • Create New Preset - Save current table state as a new preset
  • Update Existing - Sync current table state to an existing preset
  • Toggle Public/Private - Share presets with other users or keep them private
  • Set as Default - Mark a preset to load automatically
  • Toggle Visibility - Show/hide presets from quick-switch buttons
  • Delete Presets - Remove unwanted presets

Authorization

The plugin includes a policy for fine-grained access control. Customize FilamentTablePresetPolicy to define:

  • Who can view presets
  • Who can create presets
  • Who can update presets
  • Who can delete presets
  • Who can manage public/private status

Database Structure

Tables

  • filament_table_presets - Stores preset configurations
  • filament_table_preset_user - Pivot table for user-preset relationships

Customizing Table Names

Edit the published config file:

return [
    'table_name' => 'filament_table_presets',
    'pivot_table_name' => 'filament_table_preset_user',
];

Translations

The plugin comes with built-in English translations. To add your own language:

Step 1: Publish the language files (optional):

php artisan vendor:publish --tag="filament-table-presets-translations"

Step 2: Create a new language file in your application:

Create lang/vendor/filament-table-presets/{locale}/table-preset.php in your application:

<?php

return [
    'create_preset' => 'Crea un preset',
    'attach_preset' => 'Allega preset',
    'select_preset' => 'Scegli un preset',
];

Screenshots

Table with Preset Actions

Table Dark Mode Table Light Mode

Preset Management Modal

Modal Dark Mode Modal Light Mode

Drag and Drop Reordering

Drag and Drop

Testing

composer test

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.