EN ES
Home > Web development > Laravel Tutorials > How to Set Default Sorting in Filament Tables

How to Set Default Sorting in Filament Tables

Diego Cortés
Diego Cortés
September 1, 2024
How to Set Default Sorting in Filament Tables

If you have Filament, you know how to establish the predetermined order of the registers that appear in the Resource tab. In this article, you will see the message that is logged. Only you need to add the default function Sort into the method table in your Filament Resource.

To order records when creating a descendent form, use the following code:

->defaultSort('created_at', 'desc'); 

Here is a more complete example that includes additional actions to edit and delete records at hand:

->actions([
    Tables\Actions\EditAction::make(),
])
->bulkActions([
    Tables\Actions\BulkActionGroup::make([
        Tables\Actions\DeleteBulkAction::make(),
    ]),
])
->defaultSort('created_at', 'desc');

This will allow you to control how the data is displayed when you apply it from the first moment, improving the user experience and facilitating the administration of the registers.

Diego Cortés
Diego Cortés
Full Stack Developer, SEO Specialist with Expertise in Laravel & Vue.js and 3D Generalist

Categories

Page loaded in 24.71 ms