jQuery datatable分页不显示页数 [英] jquery datatable pagination not showing page counts

查看:911
本文介绍了jQuery datatable分页不显示页数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jquery数据表1.9.4填充服务器端处理表.数据已正确加载.但分页无法正常工作.实际上,它有30多个行,而下一个,上一个和页码不起作用

Hi i'm using jquery data table 1.9.4 for population server side processing tables.The data's are loading correctly. but the pagination is not working as expected. Actually it has more than 30 rows and the next,previous and page numbers not working

var sTableAllCustomers = $('#tblAllCustomers').dataTable({
                "bDestroy": true,
                "bProcessing": true,
                "bServerSide" : true,
                "bLenthChange" : false,
                "iDisplayLength": 5,
                "aLengthMenu": [[5, 10, 25, 50, -1], [5, 10, 25, 50, "All"]],
                "sPaginationType" : "full_numbers",
                "sAjaxSource" : "loadAllCustomers",
                "oLanguage" : {
                    "sSearch" : "Search By Email ID:"
                },
                "aoColumns" : [
                 {"sTitle" : "No.","mData" : null,"aTargets": [ 0 ],
                    "fnRender" : function(obj) {
                        var columnIndex = obj.oSettings._iDisplayStart + obj.iDataRow+1
                        return columnIndex;
                    }
                },
                {"sTitle" : "Email ID","mData" : "email", "bSearchable" : true},
                {"sTitle" : "Devices","mData" : "device", "bSearchable" : false},
                {"sTitle" : "App Edition","mData" : "edition", "bSearchable" : false},
                {"sTitle" : "Account Type","mData" : "accountType", "bSearchable" : false},
                {"sTitle" : "Activated Date","mData" : "activatedDate", "bSearchable" : false},
                {"mData" : "id", "bSearchable": false,
                    "mRender": function (data, type, full ) {
                         return '<a id="'+data+'" datakey="'+full['key']+'" class="btnViewMoreInAllCustomers btn tooltipped more color-sec" data-tooltip="More" data-position="left"> <i class="mdi-notification-more"></i></a>';
                      }
                }
                ],
                   "fnServerData" : function(sSource, aoData, fnCallback) {
                    $.ajax({
                     "dataType" : 'json',
                     "type" : "GET",
                     "url" : sSource,
                     "data" : aoData,
                     "success" : fnCallback
                    });
                   },
            });

服务器端代码

int totalListSize = modals != null ? modals.size() : 0;
        CustomerDataTableObject dataTableObject = new CustomerDataTableObject();
        // the total data in db for datatables to calculate page no. and
        // position
        dataTableObject.setiTotalDisplayRecords(totalListSize);
        // the total data in db for datatables to calculate page no.
        dataTableObject.setiTotalRecords(totalListSize);
        dataTableObject.setsEcho(Integer.parseInt(request.getParameter("sEcho")));
        dataTableObject.setAaData(modals);
        Gson gson = new Gson();
        String json = gson.toJson(dataTableObject);

推荐答案

您正在用存储在totalListSize变量中的相同值初始化两个参数iTotalRecordsiTotalDisplayRecords.但是,变量totalListSize保留返回的记录数,但应保留数据库中的记录总数.

You're initializing two parameters iTotalRecords and iTotalDisplayRecords with the same value stored in totalListSize variable. However variable totalListSize holds the number of records returned, but it should hold total number of records in the database.

文档:

iTotalRecords

过滤前的记录总数(即数据库中的记录总数)

Total records, before filtering (i.e. the total number of records in the database)

iTotalDisplayRecords

过滤后的记录总数(即应用过滤后的记录总数-不仅是此结果集中返回的记录数)

Total records, after filtering (i.e. the total number of records after filtering has been applied - not just the number of records being returned in this result set)

您需要分别计算数据库中的记录总数,并将其分配给iTotalRecordsiTotalDisplayRecords.

You need to calculate total number of records in the database separately and assign it to iTotalRecords and iTotalDisplayRecords.

例如,如果您有30条记录,并且仅5可以显示在一页上,则您的响应应该类似于:

For example, if you have 30 records and only 5 can be displayed on one page, your response should be something like:

{

    "sEcho": 1,
    "iTotalRecords": 30,
    "iTotalDisplayRecords": 30,
    "aaData": [
        {
            "DT_RowId": "row_8",
            "DT_RowClass": "gradeA",
            "0": "Gecko",
            "1": "Firefox 1.5",
            "2": "Win 98+ / OSX.2+",
            "3": "1.8",
            "4": "A"
        },
        // ... 4 more entries ... 
    ]
}

这篇关于jQuery datatable分页不显示页数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆