Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Spiral's avatar

orderColumn for sorting not working in yajra datatable using in laravel

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

coming error Method Yajra\DataTables\CollectionDataTable::orderColumn does not exist.

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>
0 likes
2 replies
dongun's avatar

Dump your query in json first. Datatable has a way of missing ordering up

Please or to participate in this conversation.