Closed nalcoder0913 closed 10 months ago
When no sorting column is selected:
select * from `myTable` order by `created_at` desc limit 10 offset 0
When a sorting column is selected:
select * from `myTable` order by `created_at` desc, `code` desc limit 10 offset 0
When I want to change the sorting order, I would like to remove "created_at." How can I achieve this?
$data = MyTable:latest(); return DataTables::eloquent($data) ->addIndexColumn() ->addColumn('product_id', function ($row) { return Product::find($row->product_id)->product_name; }) ->addColumn('project_id', function ($row) { return Project::find($row->project_id)->name; }) ....(more addColumn).... ->order(function ($query) { if (request()->has('order.0.column') && !empty(request()->input('order.0.column'))) { $orderColumnIndex = request()->input('order.0.column'); $orderColumn = request()->input('columns.' . $orderColumnIndex . '.data'); $orderDir = request()->input('order.0.dir'); $query->orderBy($orderColumn, $orderDir); } }) ->toJson();
I'm sorry. It seems like the issue was with the code MyTable:;latest();. I've now changed it to MyTable::query();
Summary of problem or feature request
When no sorting column is selected:
When a sorting column is selected:
When I want to change the sorting order, I would like to remove "created_at." How can I achieve this?
Code snippet of problem
System details