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
435 stars 123 forks source link

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

Closed grafxflow closed 1 year ago

grafxflow commented 1 year 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 1 year 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 1 year 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 1 year ago

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

darkons commented 1 year 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 1 year 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.