2015-11-10 67 views
0

內部MVC控制器我收到的MyTable作爲參數服務器端分頁落實數據表

public JsonResult GetListOfData(JobTable result) 
{ 
    var query = ... get data .. 
    IQueryable<MyData> resData; 
    resData.recordsFiltered = query.Skip(result.start).Take(50).AsQueryable(); 
    resData.recordsTotal = query.Count(); 
    ... 
    return Json(resData, JsonRequestBehavior.AllowGet);   
} 

內部視圖我的js代碼初始化jQuery的數據表

function drawTable() { 
      var table = $('#myTable').dataTable({ 
       processing: true, 
       serverSide: true, 
       searching: false, 
       lengthChange: false, 
       displayLength: 25, 
       order: [[5, 'desc']], 
       ajax: { 
        url: '@Url.Action("GetListOfData", "Index")', 
        data: function (d) { 
         ... 
         d.status = $('#Status').val(),       
         d.dateFrom = $('#DateFrom').val(), 
         d.dateTo = $('#DateTo').val(), 
         ...      
        } 
       }, 

       columns: [ 
        { data: 'Id' },      
        { data: 'Status' },           
        { data: 'CreatedDate' }, 
        ... 
       ], 
       columnDefs: [ 
        { 
         targets: [0, 3, 4], 
         orderable: false 
        }, 
        { 
         render: function (data, type, row) { 
          return '<a href="@Url.Action("Details", "Index")/' + data + '"><i class="glyphicon glyphicon-folder-open"></i></a>' 
         }, 
         title: '', 
         targets: 0 
        } 
       ] 
      }); 
     } 

的問題是: 我爲了成功實現服務器端分頁,我錯過了這些,我應該怎麼做才能識別視圖內的點擊數並將它作爲MyTable參數的一部分?

回答

1

我剛修好了! recordFiltered和recordsTotal應該具有相同的長度。

我在服務器端在做:

return Json(new 
     { 
      draw = param.draw, 
      recordsTotal = allData.Count(), 
      recordsFiltered = filteredData.Count(), 
      data = result 
     }, JsonRequestBehavior.AllowGet); 

現在我做:

return Json(new 
     { 
      draw = param.draw, 
      recordsTotal = allData.Count(), 
      recordsFiltered = allData.Count(), 
      data = result 
     }, JsonRequestBehavior.AllowGet);