2015-11-02 131 views
5

我試圖讓Angularjs的DataTable服務器端分頁在這個環節https://l-lin.github.io/angular-datatables/#/serverSideProcessingAngularjs的DataTable服務器端分頁

所以我用這個代碼

$scope.dtOptions = DTOptionsBuilder.newOptions() 
     .withOption('ajax', { 
        dataSrc: function(json) { 
        conole.log(json) 
        json['recordsTotal'] =json.length 
        json['recordsFiltered'] = json.length 
        json['draw']=1 
        conole.log(json) 
        return json; 
        }, 
       url: 'api/footestrecords', 
       type: 'GET' 
      }) 
     .withOption('processing', true) 
     .withOption('serverSide', true) 
     .withPaginationType('full_numbers'); 

我在DATASRC參數手動添加recordsTotal,recordsFiltered和行

,這是JSON數據前後加recordsTotal,recordsFiltered和行

JSON數據前加

[Object, Object, Object, Object, Object, Object, Object, Object, 
Object,Object, Object, Object, Object, Object, Object, Object, Object, 
Object, Object, Object, Object, Object, Object, Object, Object, Object, 
Object, Object] 

JSON數據後添加

[Object, Object, Object, Object, Object, Object, Object, Object, 
    Object, Object, Object, Object, Object, Object, Object, Object, Object, 
    Object, Object, Object, Object, Object, Object, Object, Object, 
    Object,Object, Object, recordsTotal: 28, recordsFiltered: 28, draw: 1] 

的萬阿英,蔣達清是分頁不工作,數據表顯示在一個頁面中的所有數據,當我點擊呼叫按鈕沒有任何行動。

+0

你能解決它嗎? –

+0

你在這裏犯了錯誤:'conole.log' – zygimantus

回答

1

刪除.dataSrc並使用此選項:根據

.withDataProp(function(json) { 
    console.log(json); 
    json.recordsTotal = json.response.total; 
    json.recordsFiltered = json.response.total; 
    json.draw = 1; 
    return json.response.data; 
}) 

變化json.response你的對象。