MedicOneSystems/livewire-datatables

filterable() array key as value not working

shahidkarimi opened this issue · 6 comments

$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

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.

<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>

It is untouched

So

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

is an extremely silly idea

okay. Change it according to your needs.

please update line number 29 accordingly.