PHPackages                             ymsoft/filament-table-presets - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. ymsoft/filament-table-presets

ActiveLibrary

ymsoft/filament-table-presets
=============================

A Filament plugin to save and load table presets

1.0.1(1mo ago)151.5k↓15%6[1 issues](https://github.com/yarmat/filament-table-presets/issues)MITPHPPHP ^8.2CI passing

Since Oct 25Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/yarmat/filament-table-presets)[ Packagist](https://packagist.org/packages/ymsoft/filament-table-presets)[ Docs](https://github.com/ymsoft/filament-table-presets)[ GitHub Sponsors](https://github.com/ymsoft)[ RSS](/packages/ymsoft-filament-table-presets/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (7)Dependencies (24)Versions (9)Used By (0)

Filament Table Presets
======================

[](#filament-table-presets)

[![Latest Version on Packagist](https://camo.githubusercontent.com/15254caa9d3314597ede13603eb4dbcc2c13d771d6ac3045f6fe280f523dfae9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f796d736f66742f66696c616d656e742d7461626c652d707265736574732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ymsoft/filament-table-presets)[![GitHub Tests Action Status](https://camo.githubusercontent.com/69a2b2845c2952aacfaf576611696dc405cdae31a85b9abdac83f7990378bad0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7961726d61742f66696c616d656e742d7461626c652d707265736574732f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/yarmat/filament-table-presets/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/aca4e35025f53a2a331f34b0ca0bc495e0720004394806f3fc454c35460fc1bc/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7961726d61742f66696c616d656e742d7461626c652d707265736574732f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/yarmat/filament-table-presets/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/b771bb01d09943eb9f687740d349091938ea1706da4f626ac7e2b206e8701fdf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f796d736f66742f66696c616d656e742d7461626c652d707265736574732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ymsoft/filament-table-presets)

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](art/intro.gif)](art/intro.gif)

Table of Contents
-----------------

[](#table-of-contents)

- [Features](#features)
- [Installation](#installation)
- [Configuration](#configuration)
    - [Custom Theme Setup](#custom-theme-setup)
    - [Panel Registration](#panel-registration)
    - [Polymorphic User Relationships](#polymorphic-user-relationships)
    - [Custom Modal Table](#custom-modal-table)
    - [User Model Trait](#user-model-trait)
- [Usage](#usage)
    - [Basic Setup](#basic-setup)
    - [Auto-Reset Active Preset](#auto-reset-active-preset)
    - [Working with Presets](#working-with-presets)
- [Preset Management](#preset-management)
- [Authorization](#authorization)
- [Database Structure](#database-structure)
- [Translations](#translations)
- [Screenshots](#screenshots)
- [Testing](#testing)
- [Security Vulnerabilities](#security-vulnerabilities)
- [Credits](#credits)
- [License](#license)

Features
--------

[](#features)

- 💾 **Save Table States** - Preserve filters, sorting, search, and column visibility
- 👥 **Public &amp; 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
------------

[](#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
-------------

[](#configuration)

### Custom Theme Setup

[](#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

[](#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

[](#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

[](#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

[](#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
-----

[](#usage)

### Basic Setup

[](#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

[](#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

[](#working-with-presets)

#### Apply Default Preset

[](#apply-default-preset)

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

    $this->applyDefaultPreset();
}
```

#### Retrieve Visible Preset Actions

[](#retrieve-visible-preset-actions)

Display preset quick-switch buttons in the table header:

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

#### Manage Presets Action

[](#manage-presets-action)

Add the preset management modal to your page header:

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

Preset Management
-----------------

[](#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
-------------

[](#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
------------------

[](#database-structure)

### Tables

[](#tables)

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

### Customizing Table Names

[](#customizing-table-names)

Edit the published config file:

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

Translations
------------

[](#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:

```
