How To Enable Order By Desc In Yajra Datatable Example

Hello Artisan,

In this example, I will show you how to order by asc or desc in yajra databale. So from this yajra datatables order by desc tutorial, you will learn an easy way of yajra datatables order by desc.

I will show you an simple example of laravel datatables order by desc. If you don't know how to do it, the this example is for you. let's see the below example code of laravel datatables order by desc:

  $(function () {
    var table = $('.data-table').DataTable({
        "order": [ [0, 'desc'] ],
        ajax: "{{ route('user') }}",
        columns: [
            {data: 'id', name: 'id'},
            {data: 'name', name: 'name'},
            {data: 'email', name: 'email'},
            {data: 'status', name: 'status'},
            {data: 'created_at', name: 'created_at'},
            {data: 'action', name: 'action', orderable: true, searchable: true},


Read also: Filter Data Between Two Dates in Yajra Datatables in Laravel


Just use this attribute "order": [ [0, 'desc'] ] in datatable object like above code. Hope it can help you.


#laravel #laravel-9x #yajra-datatables