数据表限制和偏移问题

时间:2016-11-30 12:18:00

标签: laravel datatable

我使用带有集合的服务器端数据表的yajra数据表。当我第一次加载页面时,数据会进入。但是当我点击下一页页面> 1 时,没有数据可用。我在查询中使用limit和offset。我的控制器就是这个

 public function getorderslist(Request $request)
  { 
      $requestData = $request->all(); /////all request data.
      $finalArrary = $this->orderlistfunction($request);
        $allordersData = new Collection($finalArrary['finalArrary']);
       $totalrecords = $finalArrary['totalrecords'];


      return Datatables::of($allordersData)->with(['recordsTotal'=>$totalrecords ,'recordsFiltered'=> $totalrecords])->make(true);
  }

我看过控制台获取数据,但未嵌入数据表数据索引中。这是我的Javascript(jQuery)代码:

var oTable = $('#orders-table')。DataTable({         处理:真的,         serverSide:true,         AJAX:         {

      url: SITE_URL+'filterfetch/orders',

      data: function (d) 
      {
          d.orderstatus ='pending';
           // d.length =100;
          //d.event_id=$('input[name=event_id]').val();
          var dt_params = $('#orders-table').data('dt_params');
          // Add dynamic parameters to the data object sent to the server
          if(dt_params)
          { 
            //alert(dt_params);
            $.extend(d, dt_params); 
          }
      }
    },
    "order": [[ 1, "desc" ]],

    columns: [
        { data: 'date', name: 'date' },
        { data: 'eventname', name: 'eventname' },
        { data: 'orderid', name: 'orderid' },
        { data: 'attempts', name: 'attempts' },
        { data: 'name', name: 'name' },
        { data: 'email', name: 'email' },
        { data: 'mobile', name: 'mobile' },
        { data: 'quantity', name: 'quantity' },
        { data: 'amount', name: 'amount' },
        { data: 'action', name: 'action' },
        { data: 'called', name: 'called' }

    ]
});

1 个答案:

答案 0 :(得分:0)

试用此代码:

var oTable = $('#orders-table').DataTable({            
    dom: "<'row'<'col-xs-12'<'col-xs-6'l><'col-xsvalidation-6'p>>r>" +
            "<'row'<'col-xs-12't>>" +
            "<'row'<'col-xs-12'<'col-xs-6'i><'col-xs-6'p>>>",
    processing: true,
    serverSide: true,
    pageLength: 25,
    order: [[0, "desc"]],
    ajax: {
        url: SITE_URL+'filterfetch/orders',
        data: function (d) {
            //d.name = $('input[name=name]').val();
        }
    },
    columns: [
        { data: 'date', name: 'date' },
        { data: 'eventname', name: 'eventname' },
        { data: 'orderid', name: 'orderid' },
        { data: 'attempts', name: 'attempts' },
        { data: 'name', name: 'name' },
        { data: 'email', name: 'email' },
        { data: 'mobile', name: 'mobile' },
        { data: 'quantity', name: 'quantity' },
        { data: 'amount', name: 'amount' },
        { data: 'action', name: 'action' },
        { data: 'called', name: 'called' }
    ],
    aoColumnDefs: [{'bSortable': false, 'aTargets': [1, 2, 3, 4]}]
});