[Vuejs]-Initialize server side multi-column sorting in Laravel Inertia Vue

0👍

recently I faced the same issue, if u are still looking for a solution here u go.

If u are using pagination, u don’t need to create an additional API, you can use the GET u are using to show the datas.

In your component is better using Inertia, something like this wuold work:

setOrderBy(orderBy) {
            this.currentContactSortColumn = orderBy
            this.$inertia.get(route('show'), {
                'sort': orderBy,
                //'direction': 'asc'
            }, {
                preserveState: true
            })

        },

Then in the controller, u have to check for the sort if is empty set a default value

(empty($request->sort)) ? $request->sort = 'default_value' : '';

And last after using paginate

$contacts->appends(['sort' => $request->sort]);

🙂

Leave a comment