2015-11-02 87 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你的对象。