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

filterable() array key as value not working #552

Closed shahidkarimi closed 1 year ago

shahidkarimi commented 1 year ago
$filters = [
'12' => 'Flagged',
'14' => 'Out Lawed'
]

Column::name('status')->label('Status')->filterable($filters)

This is creating html like

<option value="Flagged">Flagged</option>

It should print this:

<option value="12">Flagged</option>

Is this an issue or not implemented?

Update: After digging this sh** more, I discovered that if the key is a numeric value it is replaced by the value. What is going on? @rameezmeans

rameezmeans commented 1 year ago

Please publish the the resources and you will see the implementation in 'resources/views/livewire/datatables/filters/select.blade.php'. You may change that as you want.

shahidkarimi commented 1 year ago
<div x-data class="flex flex-col">
    <div class="flex">
        <select
            x-ref="select"
            name="{{ $name }}"
            class="w-full h-8 m-1 text-sm leading-4 block rounded-md border-gray-300 shadow-sm focus:border-blue-300 focus:ring focus:ring-blue-200 focus:ring-opacity-50"
            wire:input="doSelectFilter('{{ $index }}', $event.target.value)"
            x-on:input="$refs.select.value=''"
        >
            <option value=""></option>
            @foreach($options as $value => $label)
                @if(is_object($label))
                    <option value="{{ $label->id }}">{{ $label->name }}</option>
                @elseif(is_array($label))
                    <option value="{{ $label['id'] }}">{{ $label['name'] }}</option>
                @elseif(is_numeric($value))
                    <option value="{{ $label }}">{{ $label }}</option>
                @else
                    <option value="{{ $value }}">{{ $label }}</option>
                @endif
            @endforeach
        </select>
    </div>

    <div class="flex flex-wrap max-w-48 space-x-1">
        @foreach($this->activeSelectFilters[$index] ?? [] as $key => $value)
        <button wire:click="removeSelectFilter('{{ $index }}', '{{ $key }}')" x-on:click="$refs.select.value=''"
            class="m-1 pl-1 flex items-center uppercase tracking-wide bg-gray-300 text-white hover:bg-red-600 rounded-full focus:outline-none text-xs space-x-1">
            <span>{{ $this->getDisplayValue($index, $value) }}</span>
            <x-icons.x-circle />
        </button>
        @endforeach
    </div>
</div>
shahidkarimi commented 1 year ago

It is untouched

shahidkarimi commented 1 year ago

So

@elseif(is_numeric($value))
                    <option value="{{ $label }}">{{ $label }}</option> 

is an extremely silly idea

rameezmeans commented 1 year ago

okay. Change it according to your needs.

rameezmeans commented 1 year ago

please update line number 29 accordingly.