thesimons's avatar

Ordering records with Filament

Hello,

I have a database table with some records. I'd like to decide the order how these records are showed for users (I have created an order field for that).

Is there a way, with Filament, to order them? Like a drag and drop in the table or arrow up/down.

Thanks, Simon

0 likes
4 replies
Eimmaarose's avatar

Yes — you can definitely order records in Filament using your custom order field. You have two good options depending on how interactive you want the sorting to be:

Option 1: Simple ordering (no drag-and-drop)

Just tell Filament to sort the table using your order column:

public static function getEloquentQuery(): Builder { return parent::getEloquentQuery()->orderBy('order'); }

This will always display records in the order you set.

You can also add up/down buttons inside the table:

Tables\Actions\Action::make('move_up') ->action(fn ($record) => $record->decrement('order')),

Tables\Actions\Action::make('move_down') ->action(fn ($record) => $record->increment('order')),

Option 2: Drag & Drop Sorting (recommended)

Filament supports drag-and-drop ordering using the Spatie Eloquent Sortable package.

  1. Install the package: composer require spatie/eloquent-sortable

  2. Add this to your model: use Spatie\EloquentSortable\Sortable; use Spatie\EloquentSortable\SortableTrait;

class YourModel extends Model implements Sortable { use SortableTrait;

public $sortable = [
    'order_column_name' => 'order',
    'sort_when_creating' => true,
];

}

  1. Enable reordering in your Filament Resource: public static function canReorder(): bool { return true; }

Now you’ll see a drag-handle in your table and can reorder records with the mouse. Filament will automatically update your order column.

Summary

Yes, ordering is possible You can use arrows, automatic sorting, or drag-and-drop Drag-and-drop is built-in when using Spatie’s sortable package

If you want, I can show you the full working code for your specific resource.

Please or to participate in this conversation.