Donations Appreciated

Doing nothing for others is the undoing of ourselves. - Horace Mann

EloquentController.php - Order Column API

Order column has a special variable $1 which is being replace as the order direction value of the request.

->orderColumn('name', 'email $1')

In this demo, when name column is sorted, it will be sorted by email instead.

Id Name Email Created At Updated At


    public function getOrderColumn(Request $request)
        if ($request->ajax()) {
            return Datatables::of(User::query())
                ->orderColumn('name', 'email $1')

        return view('datatables.eloquent.order-column', ['title' => 'Order Column API']);


        processing: true,
        serverSide: true,
        ajax: '',
        columns: [
            {data: 'id', name: 'id'},
            {data: 'name', name: 'name'},
            {data: 'email', name: 'email'},
            {data: 'created_at', name: 'created_at'},
            {data: 'updated_at', name: 'updated_at'}