protonemedia / inertiajs-tables-laravel-query-builder

Inertia.js Tables for Laravel Query Builder
https://protone.media/en/blog/introducing-inertiajs-tables-a-datatables-like-package-for-laravel-query-builder
MIT License
437 stars 131 forks source link

I there any way to selectFilter sort by if the value is numerical #104

Closed grafxflow closed 2 years ago

grafxflow commented 2 years ago

I there any way to use the selectFilter and have it sortBy using the value if its numerical?

$table->selectFilter('language_code', [
        'en' => 'Engels',
        'nl' => 'Nederlands',
    ]);

So for example:

$table->selectFilter('model', [
        4 => 'Name1',
        1 => 'Name2',
        2 => 'Name3',
        3 => 'Name4',
    ]);

So it outputs:

<option value="1"> Name2 </option>
<option value="2"> Name3 </option>
<option value="3"> Name4 </option>
<option value="4"> Name1 </option>
darkons commented 2 years ago

Please, stop asking about things not related to this package. If you want to sort an array, just check google for help.

use Illuminate\Support\Arr;

$table->selectFilter('model', Arr::sort([
    4 => 'Name1',
    1 => 'Name2',
    2 => 'Name3',
    3 => 'Name4',
]));
grafxflow commented 2 years ago

But what I am noticing is your function requires the options to be an array not an object and vuejs automatically ignores all the keys no matter what order Laravel places them in and just puts them numerically.

grafxflow commented 2 years ago

In fact ignore it will be easier to fork and make the appropriate amends. Thanks for your help.

darkons commented 2 years ago

This is not my package. I'm only an user.

The options must be and array because you are working in PHP and arrays are easier to handle. Just sort your array as you want and the options will be displayed like that.

grafxflow commented 2 years ago

As mentioned vuejs ignores the array int key order by default for select inputs, but this package is a nice starting to expand upon.