【问题标题】:Angularjs Datatable server side paginationAngularjs Datatable 服务器端分页
【发布时间】:2015-11-02 10:49:52
【问题描述】:

我正在尝试在此链接 https://l-lin.github.io/angular-datatables/#/serverSideProcessing 中制作 Angularjs 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和row

这是添加recordsTotal,recordsFiltered和row之前和之后的json数据

添加前的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]

问题是分页不起作用,数据表在一页中显示所有数据,当我点击分页按钮时没有任何动作。

【问题讨论】:

  • 你在这里犯了错误:conole.log

标签: javascript jquery angularjs datatables angular-datatables


【解决方案1】:

返回的 JSON 格式应该是:

{
    data: [{Object},{Object},{Object},{Object}…]
    draw: "1"
    recordsFiltered: 91
    recordsTotal: 91
}

你可以从这里获得关于Datatables server-side paging, sorting and filtering in angularjs的完整教程

【讨论】:

    【解决方案2】:

    删除.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。

    【讨论】:

      【解决方案3】:
      The return data must be list of object ["data"]=[{name:john,id:1},{name:jason,id:2}].
      
      Try
        .withOption('ajax', {
                        dataSrc: function(data) {                 
                         return data.data;
                           }
                        })
      Else,
             .withOption('ajax', {
                        "dataSrc": "data"
                        }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-04-30
        • 1970-01-01
        • 2015-06-10
        • 1970-01-01
        • 2015-08-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多