Usage

The Column class is used in the getColumns method of your Livewire component to define the columns that will be displayed in the grid.

use BoredProgrammers\LaraGrid\Components\ColumnComponents\Column;
use BoredProgrammers\LaraGrid\Components\ColumnComponents\ColumnGroup;
use BoredProgrammers\LaraGrid\Components\ColumnComponents\ActionButton;
use BoredProgrammers\LaraGrid\Filters\TextFilter;
use BoredProgrammers\LaraGrid\Filters\SelectFilter;
use BoredProgrammers\LaraGrid\Filters\DateFilter;

protected function getColumns(): array
{
    return [
            Column::make('email', 'attributes.email')
                ->setFilter(TextFilter::make()),

            Column::make('first_name', 'First Name')
                ->setFilter(TextFilter::make()),

            Column::make('last_name', 'last_name')
                ->setFilter(TextFilter::make()),
                            
            Column::make('role', 'attributes.role')
                ->setFilter(
                    SelectFilter::make()
                        ->setOptions([
                            'admin' => 'Admin',
                            'user' => 'User',
                        ])
                ),

            Column::make('created_at', 'attributes.created_at')
                ->setFilter(DateFilter::make()),
    
            ColumnGroup::make('attributes.actions')
                ->setColumns([
                    ActionButton::make('attributes.detail')
                        ->setColumnTag('a')
                        ->setRenderer(fn(User $user) => view('test'))
                        ->setAttributes(function (User $user) {
                            return [
                                'wire:click.prevent' => 'download(' . $user->id . ')',
                            ];
                        }),
                    ActionButton::make('attributes.delete')
                        ->setColumnTag('a')
                        ->setAttributes(function (User $user) {
                            return [
                                'wire:click.prevent' => 'download(' . $user->id . ')',
                            ];
                        }),
                ]),
        // Add more columns as needed
    ];
}

Last updated