MedicOneSystems / livewire-datatables

Advanced datatables using Laravel, Livewire, Tailwind CSS and Alpine JS
https://livewire-datatables.com/
MIT License
1.19k stars 258 forks source link

how to filter value in array in columns? in method getAtrProperty #440

Open abbasgholia opened 2 years ago

abbasgholia commented 2 years ago

how to filter "blue" and "red" and "pink" in columns? in filterable

please see the code below :

        , Column::callback(['color'],function ($color){
            if ($color == 1){
                return "blue";
            }elseif($color == 2){
                return "red";
            }else{
                    return "pink"; 
                }
        })
            ->label('Status')
            ->filterable(['blue','red','pink'])
levibaldelomar commented 2 years ago

I suggest to use "filterOn" at the end, something like:

->filterable(['blue','red','pink'])
->filterOn('CASE ' .
  'WHEN color = 1 THEN "blue" ' .
  'WHEN color = 2 THEN "red" ' .
  'ELSE "pink" ' .
'END')