Kyslik / column-sortable

Package for handling column sorting in Laravel 5/6/7/8
MIT License
641 stars 105 forks source link

Configurable parameters #192

Open robbielove opened 2 years ago

robbielove commented 2 years ago

I would like it if the params 'direction', 'sort' were hardcoded as a default config setting rather than hardcoded in general.

Personally, I prefer to use 'order' as 'direction' and it causes the need for both parameters in the URL because I just use 'order' and force it to populate direction so that sortable works.

This would also allow them to be translated too.

eg. something like this (i just got a random bit of code)


        $sortParamName = config('columnsortable.sort_param_name', 'sort');
        $directionParamName = config('columnsortable.direction_param_name', 'direction');

        if (is_string($array)) {
            return [$sortParamName => $array, $directionParamName => $defaultDirection];
        }

        return (key($array) === 0) ? [$sortParamName => $array[0], $directionParamName => $defaultDirection] : [
            $sortParamName      => key($array),
            $directionParamName => reset($array),
        ];