Reorderable Columns is a plugin for Filament that allows users to reorder table columns via drag-and-drop. The new column order can be saved either in the session or persisted in the database (per user).
Install the package via Composer:
composer require bostos/reorderable-columns
Then, publish and run the migrations to create the reorderable_columns_orders
table:
php artisan vendor:publish --tag="reorderable-columns-migrations"php artisan migrate
Optionally, publish the configuration file:
php artisan vendor:publish --tag="reorderable-columns-config"
In your AdminPanelProvider.php
(or another panel provider), register the plugin inside the panel()
method. You can choose the persistence strategy:
persistToSession()
(default) – Saves order in the session (lost on logout).persistToDatabase()
– Persists per-user column order in the database.use Bostos\ReorderableColumns\ReorderableColumnsPlugin; public function panel(Panel $panel): Panel{ return $panel // ... other configurations ->plugin( ReorderableColumnsPlugin::make() ->persistToSession() // or ->persistToDatabase() );}
In your ListRecords page class (e.g. app/Filament/Resources/UserResource/Pages/ListUsers.php
), use the HasReorderableColumns
trait and override the $view
property.
use Bostos\ReorderableColumns\Concerns\HasReorderableColumns;use Filament\Resources\Pages\ListRecords; class ListUsers extends ListRecords{ use HasReorderableColumns; protected static string $view = 'filament.resources.users.pages.list-users';}
💡 Don't forget to create the custom view in Step 4.
In your resource file (e.g. UserResource.php
), chain the ->reorderableColumns()
method to your table definition. Provide a unique key (usually table or model name).
use Filament\Tables\Table; public static function table(Table $table): Table{ return $table ->columns([ // your columns ]) ->filters([ // your filters ]) ->actions([ // your actions ]) ->reorderableColumns('users'); // Use a unique key}
Since Filament’s table component doesn’t allow custom HTML attributes on the outer wrapper, you’ll need to override the view and wrap the table manually.
At the path defined in Step 2, create:
resources/views/filament/resources/users/pages/list-users-reorderable.blade.php
Copy the content from:
vendor/filament/filament/resources/views/resources/pages/list-records.blade.php
Paste it into your custom Blade file.
Locate the line:
{{ $this->table }}
Wrap it in a div
with a data-reorderable-columns
attribute:
{{-- resources/views/filament/resources/users/pages/list-users-reorderable.blade.php --}} <x-filament-panels::page> {{-- Required wrapper for reordering --}} <div data-reorderable-columns="users"> {{ $this->table }} </div> </x-filament-panels::page>
Make sure the value (users
) matches the key passed in ->reorderableColumns()
.
Please refer to the CHANGELOG for details on recent changes.
Contributions are welcome! Please see the CONTRIBUTING guide for details.
If you discover a security vulnerability within this package, please send an e-mail to nikolast_metal@hotmail.com. All security vulnerabilities will be promptly addressed.
The MIT License (MIT). See the LICENSE file for more details.