0

OrderColumn not working for sorting the list according to updated_at but not working.

This is my code you can see

$product = Product::query()->get();

return Datatables::of($product )
            ->orderColumn('updated_at', 'DESC')
            ->make(true);

Javascript code

<script>
        $(document).ready(function(){
            var columns = [
                { 
                    data: 'name', 
                    name: 'name', 
                    searchable: true 
                },
            columns.push({
                    data: 'action', 
                    name: 'action',                      
                    orderable: false,
                    searchable: "false",
                    className: "text-center"
                });
            $('#product-table').DataTable({  
                pageLength: 25,              
                processing: true,
                serverSide: true,                                                 
                ajax: {
                    url: '{{ route('products.dt') }}',
                },
                columns: columns,
            });                                                           
        });
    </script>
5
  • @kamleshPaul you can see my code I have upload Commented Sep 30, 2020 at 6:01
  • @kamleshPaul bro...It's Not working Commented Sep 30, 2020 at 6:08
  • Bro... latest() getting according to created_at column base I want to according to updated_at column base listing Commented Sep 30, 2020 at 6:14
  • Also, It's not working Commented Sep 30, 2020 at 6:24
  • $kamlesh Paul bro... If $product = Product::query()->orderBy('updated_at', 'DESC'); I'm using this then sorting correctly but datatable not working... Commented Sep 30, 2020 at 6:26

1 Answer 1

1

The problem is that JQuery Datatables is performing its own sort after receiving the data. So the sort on the server is ignored.

I have run into the same issue, but have not yet found a solution. I am thinking about adding an extra hidden column to sort the data, but this is not a great solution either.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.