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.

Article information

Published: September 1, 2024
Category: Laravel Tutorials
Reading time: 5-8 minutes
Difficulty: Intermediate

Key tips

1

Take your time to understand each concept before moving on to the next one.

2

Practice the examples in your own development environment for better understanding.

3

Don't hesitate to review the additional resources mentioned in the article.

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

Frequently Asked Questions

Categories

Page loaded in 25.75 ms