DataTable没有显示分页按钮和记录信息-JQuery

DataTable not showing pagination buttons and records info - JQuery

本文关键字:记录 信息 -JQuery 按钮 分页 显示 DataTable      更新时间:2024-03-21

使用Datatable插件进行分页,我无法让它显示分页按钮和记录信息("显示Y个记录中的X个")。当我从表上方的下拉菜单中选择页面大小时,它可以正确地获取记录,但由于某种原因,它没有显示分页按钮。

我的猜测是,它必须知道表的Total Record计数,我给它的是,在"iTotalRecords":10000部分,我的表中有1000条记录,但它仍然没有用。我到底错过了什么?

它正在正确传递start(页码)和length(页面大小)参数。下面是我的代码,

$('#leadDetailTable').dataTable({
        "processing": true,
        "serverSide": true,
        "info": true,
        "stateSave": true,
        "lengthMenu": [[10, 50, 100, 500], [10, 50, 100, 500]],
        "iTotalRecords": 10000,
        "iDisplayLength": 10,
        "searching": false,
        "scrollY": false,
        "scrollX": false,
        "ajax":{
            type: 'POST',
            url: '@Url.Action("SearchLeads", "ResourceManagement")',
            data: args,
            success: function (result) {
                /* Do things with result */
            },
        }
    });

您是否尝试添加以下参数:

 "bPaginate":true,
 "sPaginationType":"full_numbers",
 "bLengthChange": true,
 "bInfo" : true

我遇到了同样的问题,这是因为我从服务器端返回了错误的recordsFiltered值。确保recordsTotal值表示表中的记录(行)数,recordsFiltered值表示总行中应隐藏的行数。DataTables使用这些信息来创建分页按钮。

添加以下属性

"pagingType": "full_numbers"

ajax请求返回的响应是什么?它应该包括以下内容:

{
    data: <the array of row data>,
    draw: <the same value the request had for its draw value>,
    recordsTotal: <the total number of records>,
    recordsFiltered: <the total number of records after filtering>
}

如果你不想让它说"从x条记录中筛选",那么在筛选后对记录进行计数,并将recordsTotal和recordsFiltered都设置为该值。