jquery Laravel Yajra DataTables默认条件排序

2w3rbyxf  于 11个月前  发布在  jQuery
关注(0)|答案(1)|浏览(112)

我有一个使用yajra的数据表,我有一个名为“status”的列。“status”列包含-2:Rejected By Finance,-1:Rejected By Marketing,0:Pending,1:Accepted By Marketing,2:Accepted By Finance。
所以我想通过我的表ASCENDING默认排序状态> 0,但yajra数据表不支持在服务器端排序。我如何才能达到这个条件。谢谢

var table = $('#example').DataTable({
            processing: true,
            serverSide: true,
            order: [[1,'desc']],
            ajax: {
                url: "{{ route('voucher.data') }}",
                data:function (d) {
                    d.merchant = merchant? merchant : '';
                    d.status = status? status : '';
                    d.daterange = daterange? daterange : '';
                },
                type:'POST',
            },
            columns: [
              {data: 'id', name: 'id'},
              {data: 'requested_date', name: 'requested_date'},
              {data: 'merchant.nama', name: 'merchant.nama'},
              {data: 'total', name: 'total'},
              {data: 'status', name: 'status', className: "text- 
               center"},
              {data: 'action', name: 'action', className: "text- 
              center", visible: approvalAccess, orderable:false, 
              sortable:false},
            ]
        });

字符串
Yajra Datatables Laravel Order By with Condition.

gj3fmq9x

gj3fmq9x1#

你必须把正确的列排序,目前你订购的order: [[1,'desc']]需要[[4,'asc']]

var table = $('#example').DataTable({
            processing: true,
            serverSide: true,
            order: [[4,'asc']],
            ajax: {
                url: "{{ route('voucher.data') }}",
                data:function (d) {
                    d.merchant = merchant? merchant : '';
                    d.status = status? status : '';
                    d.daterange = daterange? daterange : '';
                },
                type:'POST',
            },
            columns: [
              {data: 'id', name: 'id'},
              {data: 'requested_date', name: 'requested_date'},
              {data: 'merchant.nama', name: 'merchant.nama'},
              {data: 'total', name: 'total'},
              {data: 'status', name: 'status', className: "text- 
               center"},
              {data: 'action', name: 'action', className: "text- 
              center", visible: approvalAccess, orderable:false, 
              sortable:false},
            ]
        });

字符串
您也可以通过服务器端订购:https://yajrabox.com/docs/laravel-datatables/master/order-column

相关问题