Installation:
composer require bostos/reorderable-columns
php artisan vendor:publish --provider="Bostos\ReorderableColumns\ReorderableColumnsServiceProvider" --tag="migrations"
php artisan migrate
Enable in Filament Table: Add the trait to your table class:
use Bostos\ReorderableColumns\Concerns\ReorderableColumns;
class MyTable extends Table
{
use ReorderableColumns;
// ...
}
First Use Case:
protected function getTableColumns(): array
{
return [
Tables\Columns\TextColumn::make('name'),
Tables\Columns\TextColumn::make('email'),
Tables\Columns\TextColumn::make('created_at'),
];
}
The drag-and-drop UI appears automatically in the table header.
Define Columns:
protected function getTableColumns(): array
{
return collect($this->columns)->mapWithKeys(fn ($column) => [
$column->getName() => $column,
]);
}
Configure Storage Driver:
protected static ?string $reorderableColumnsDriver = 'database'; // or 'session'
Customize Persistence:
protected static ?string $reorderableColumnsModel = \App\Models\User::class;
protected static ?string $reorderableColumnsAttribute = 'column_order';
getTableColumns() to dynamically adjust columns based on user roles or permissions.visibleOn() to ensure only visible columns are reorderable.booted():
public static function booted(): void
{
static::defaultReorderableColumns(['name', 'email', 'created_at']);
}
protected static bool $reorderableColumnsEnabled = false;
Migration Issues:
reorderable_columns_orders table exists. Run php artisan migrate if missing.column_order JSON column exists.Column Name Conflicts:
getName() to debug:
dd($this->getTableColumns()->keys());
Session Driver Quirks:
$user = auth()->user();
dd($user->column_order); // For database driver
php artisan cache:clear
php artisan view:clear
Custom Storage Logic:
Override getReorderableColumnsOrder() to fetch orders from a non-standard location:
protected function getReorderableColumnsOrder(): ?array
{
return Cache::get('custom_column_order_' . auth()->id());
}
Event Hooks:
Listen for order changes via ReorderableColumnsSaved event:
event(new ReorderableColumnsSaved($table, $newOrder));
UI Customization: Modify the drag handle via Blade:
{{ $column->getReorderableHandle() }}
Or override the default handle in your table’s configure():
$this->configureUsing(new class {
public function configureReorderableColumns(): void
{
ReorderableColumns::make()
->handleIcon('heroicon-o-drag')
->handleWidth(40);
}
});
->remember() on the model to avoid querying on every request.How can I help you explore Laravel packages today?