DEV Community

Horacio Degiorgi
Horacio Degiorgi

Posted on

2

Mejoras en las tablas

Algunas mejoras en las listas de Filament.

Description (o linea adicional en la celda)

 Tables\Columns\TextColumn::make('name')->searchable()->sortable()->wrap()
                ->description(fn (Repository $record): string => $record->institution->name??'')

Enter fullscreen mode Exit fullscreen mode

Image description

Badges (distintivo) en campo de tipo texto

//campo type tiene varios valores definidos en un array (ojs->OJS, etc) 
Tables\Columns\BadgeColumn::make('type')->enum(Repository::$typesform),
Enter fullscreen mode Exit fullscreen mode

Image description

Ocultar columnas

con el método ->toggleable(isToggledHiddenByDefault: true) se puede ocultar la Columna y luego activarla desde el ícono de la derecha.

Actualizar valor desde la tabla

Image description

Con el método action se puede disparar una actualizacion en la celda.

    ->action(function($record, $column) {
        $name = $column->getName();
        $record->update([
            $name => !$record->$name
        ]);
    });
Enter fullscreen mode Exit fullscreen mode

Definir orden default

// en la definición del recurso 
protected function getDefaultTableSortColumn(): ?string
        {
            return 'id';
        }

    protected function getDefaultTableSortDirection(): ?string
        {
            return 'desc';
        }
Enter fullscreen mode Exit fullscreen mode

Enlazar a otro modelo

Se puede crear una macro en el método Boot de AppServiceProvider y enlazar entre modelos usando la función linkRecord luego. Fuente (el modelo dependiente está conectado al modelo institution con la columna name)
en lugar de

Tables\Columns\TextColumn::make('institution.name')
->url(fn (Library $record): string => route('filament.resources.institutions.view', ['record' => $record->institution_id]))
Enter fullscreen mode Exit fullscreen mode

Se puede usar

Tables\Columns\TextColumn::make('institution.name')->linkRecord('view')

Enter fullscreen mode Exit fullscreen mode

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay