PHP code example of dvarilek / filament-table-select

1. Go to this page and download the library: Download dvarilek/filament-table-select library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dvarilek / filament-table-select example snippets


use Dvarilek\FilamentTableSelect\Components\Form\TableSelect;

$form
    ->schema([
        TableSelect::make('clients')
            ->relationship('clients', 'name')
    ])

use Dvarilek\FilamentTableSelect\Components\Form\TableSelect;

$form
    ->schema([
        TableSelect::make('clients')
            ->relationship('clients', 'name')
            ->multiple()
    ])

use Dvarilek\FilamentTableSelect\Components\Form\TableSelect;

$form
    ->schema([
        TableSelect::make('clients')
            ->relationship('clients', 'name')
            ->multiple()
            ->minItems(1)
            ->maxItems(3)
    ])

use Dvarilek\FilamentTableSelect\Components\Form\TableSelect;

$form
    ->schema([
        TableSelect::make('clients')
            ->relationship('clients', 'name')
            ->multiple()
            ->optionColor('success')
    ])

use Dvarilek\FilamentTableSelect\Components\Form\TableSelect;

$form
    ->schema([
        TableSelect::make('clients')
            ->relationship('clients', 'name')
            ->multiple()
            ->optionIcon('heroicon-o-bell')
    ])

use Dvarilek\FilamentTableSelect\Components\Form\TableSelect;

$form
    ->schema([
        TableSelect::make('clients')
            ->relationship('clients', 'name')
            ->multiple()
            ->getOptionColorFromRecordUsing(function (Client $record) {
                return match ($record->status) {
                    'lead' => 'primary',
                    'closed' => 'success',
                    'lost' => 'gray',
                    'active' => 'danger',
                    default => 'primary'
                };
            })
    ])

use Dvarilek\FilamentTableSelect\Components\Form\TableSelect;

$form
    ->schema([
        TableSelect::make('clients')
            ->relationship('clients', 'name')
            ->multiple()
            ->getOptionIconFromRecordUsing(function (Client $record) {
                return match ($record->status) {
                    'lead' => 'heroicon-o-light-bulb',     
                    'closed' => 'heroicon-o-check-circle',   
                    'lost' => 'heroicon-o-x-circle',      
                    'active' => 'heroicon-o-bolt',           
                    default  => 'heroicon-o-question-mark-circle', 
                };
            })
    ])

use Dvarilek\FilamentTableSelect\Components\Form\TableSelect;

$form
    ->schema([
        TableSelect::make('clients')
            ->relationship('clients', 'name')
            ->multiple()
            ->getOptionLabelFromRecordUsing(function (Client $record) {
                 return "{$record->first_name} {$record->last_name} - {$record->status}";
            })
    ])

use Dvarilek\FilamentTableSelect\Components\Form\TableSelect;
use Filament\Support\Enums\ActionSize;

$form
    ->schema([
        TableSelect::make('clients')
            ->relationship('clients', 'name')
            ->multiple()
            ->optionSize(ActionSize::Large)
    ])

use Dvarilek\FilamentTableSelect\Components\Form\TableSelect;
use Filament\Support\Enums\IconSize;

$form
    ->schema([
        TableSelect::make('clients')
            ->relationship('clients', 'name')
            ->multiple()
            ->optionIconSize(IconSize::Large)
    ])

use Dvarilek\FilamentTableSelect\Components\Form\TableSelect;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;

TableSelect::make('clients')
    ->relationship('clients', 'name')
    ->selectionTable(function (Table $table) {
        return $table
            ->heading('Active Clients') 
            ->columns([
                TextColumn::make('name')
            ])
            ->modifyQueryUsing(fn (Builder $query) => $query->where('status', 'active'));
    })

use Dvarilek\FilamentTableSelect\Components\Form\TableSelect;

TableSelect::make('clients')
    ->relationship('clients', 'name')
    ->tableLocation(ClientResource::class)

use Dvarilek\FilamentTableSelect\Components\Form\TableSelect;
use Dvarilek\FilamentTableSelect\Components\Livewire\SelectionTable;
use Illuminate\Database\Eloquent\Builder;
use Filament\Tables\Table;
use Filament\Forms\Get;

TableSelect::make('employees')
    ->relationship('employees', 'name')
    ->multiple()
    ->selectionTableArguments(function (Get $get) {
        return [
            // Suppose there is a branch_id field present in the schema
            'branch_id' => $get('branch_id'), 
        ];
    })
    ->tableLocation(EmployeeResource::class)
    ->selectionTable(fn (Table $table) => $table
        ->modifyQueryUsing(function (Builder $query, SelectionTable $livewire) {
            $branchId = $livewire->arguments['branch_id'] ?? null;
            
            if ($branchId) {
                $query->where('branch_id', $branchId);
            }
            
            return $query;
        })
    )

use Dvarilek\FilamentTableSelect\Components\Form\TableSelect;

TableSelect::make('clients')
    ->relationship('clients', 'name')
    ->tableLocation(ClientResource::class)
    ->selectionTableLivewire(CustomSelectionTable::class);

use Dvarilek\FilamentTableSelect\Components\Form\TableSelect;
use Filament\Forms\Components\Actions\Action;

TableSelect::make('clients')
    ->relationship('clients', 'name')
    ->selectionAction(function (Action $action) {
        return $action
            ->icon('heroicon-o-user-plus') 
            ->modalHeading('Select Clients') 
            ->slideOver(false);
    })

use Dvarilek\FilamentTableSelect\Components\Form\TableSelect;
use Filament\Forms\Components\Actions\Action;
use Filament\Support\Enums\Alignment;

TableSelect::make('clients')
    ->relationship('clients', 'name')
    ->selectionAction(function (Action $action) {
        return $action
            ->icon('heroicon-o-user-plus') 
            ->modalHeading('Select Clients') 
            ->slideOver(false);
    })
    ->selectionActionAlignment(Alignment::End)

use Filament\Support\Enums\Alignment;

->selectionAction(alignment: Alignment::Center)

use Dvarilek\FilamentTableSelect\Components\Form\TableSelect;
use Filament\Forms\Components\Actions\Action;

TableSelect::make('clients')
    ->relationship('clients', 'name')
    ->selectionAction(function (Action $action) {
        return $action
            ->icon('heroicon-o-user-plus') 
            ->modalHeading('Select Clients') 
            ->slideOver(false);
    })
    ->triggerSelectionActionOnInputClick() 

    ->selectionAction(shouldTriggerSelectionActionOnInputClick: true)

use Dvarilek\FilamentTableSelect\Components\Form\TableSelect;

TableSelect::make('clients')
    ->relationship('clients', 'name')
    ->

use Dvarilek\FilamentTableSelect\Components\Form\TableSelect;

TableSelect::make('clients')
    ->relationship('clients', 'name')
    ->

->

use Dvarilek\FilamentTableSelect\Components\Form\TableSelect;
use Dvarilek\FilamentTableSelect\Enums\SelectionModalActionPosition;

TableSelect::make('clients')
    ->relationship('clients', 'name')
    ->

use Dvarilek\FilamentTableSelect\Enums\SelectionModalActionPosition;

->

use Dvarilek\FilamentTableSelect\Components\Form\TableSelect;

TableSelect::make('clients')
    ->relationship('clients', 'name')
    ->createOptionForm(ClientResource::form(...))
    ->createOptionUsing(function (array $data) {
        // Create related record using...
    })
    ->createOptionAction(function () {
        // Configure the action...
    })

use Dvarilek\FilamentTableSelect\Components\Form\TableSelect;
use Dvarilek\FilamentTableSelect\Enums\SelectionModalActionPosition;
use Filament\Forms\Form;

TableSelect::make('clients')
    ->relationship('clients', 'name')
    ->createOptionForm(fn (Form $form) => ClientResource::form($form))
    ->createOptionActionPosition(SelectionModalActionPosition::TOP_LEFT)

use Dvarilek\FilamentTableSelect\Components\Form\TableSelect;

public function boot(): void
{
    TableSelect::configureUsing(static function (TableSelect $tableSelect): void {
        $tableSelect->