jquery 数据表分页不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44195805/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 17:21:07  来源:igfitidea点击:

jquery datatables pagination not working

jquerypaginationdatatables

提问by parlad

I am new to jquery datatables, I had a simple function which call ajax and map the response into datatables, that is working but , the pagination is not working properly , any suggestion would be greate. Here is my code.

我是 jquery 数据表的新手,我有一个简单的函数,它调用 ajax 并将响应映射到数据表中,这是有效的,但是,分页无法正常工作,任何建议都会很棒。这是我的代码。

    function loadJson() {

    $('#datatable')
            .dataTable(
                    {
                        "bProcessing" : true,
                        "bPaginate" : true,
                        "bServerSide" : true,
                        "sServerMethod" : "GET",
                        "sAjaxSource" : "${pageContext.request.contextPath}/emi/calculate?jsonValue="
                                + jsonData,
                        "sAjaxDataProp" : "",
                        "fnRowCallback" : function(nRow, aData,
                                iDisplayIndex) {
                            $("td:first", nRow).html(iDisplayIndex + 1);
                            return nRow;
                        },

                        "aoColumns" : [ {
                            "mData" : null
                        }, {
                            "mData" : "emiDate"
                        }, {
                            "mData" : "principle"
                        }, {
                            "mData" : "interestAmount"
                        }, {
                            "mData" : "emi"
                        }, {
                            "mData" : "loanOutstanding"
                        } ]
                    });
}

I got thisoutput , the problem is , Show entries is not working and i only have 11 record and i got 1,2,3,4 page number which should only be 1, 2 and only 10 record need to be there . What did i miss here ?

我得到了这个输出,问题是,显示条目不起作用,我只有 11 条记录,我得到了 1、2、3、4 页码,应该只有 1、2 和 10 条记录需要在那里。我在这里错过了什么?

回答by Trimantra Software Solution

You have to add this,

你必须添加这个,

   "pagingType": "full_numbers",
   "paging": true,
   "lengthMenu": [10, 25, 50, 75, 100],

回答by Jay

Try to use this property in your datatable declaration

尝试在您的数据表声明中使用此属性

     function loadJson() {

    $('#datatable')
            .DataTable(
                    {

                        "sServerMethod" : "GET",
                        "sAjaxSource" : "${pageContext.request.contextPath}/emi/calculate?jsonValue="
                                + jsonData,
                        "sAjaxDataProp" : "",


                        "aoColumns" : [ {
                            "mData" : null
                        }, {
                            "mData" : "emiDate"
                        }, {
                            "mData" : "principle"
                        }, {
                            "mData" : "interestAmount"
                        }, {
                            "mData" : "emi"
                        }, {
                            "mData" : "loanOutstanding"
                        } ],
                        "bProcessing" : true,
                        "bPaginate" : true,
                        "bServerSide" : true
                    });

}

回答by R J

https://stackoverflow.com/posts/38213104/revisions

https://stackoverflow.com/posts/38213104/revisions

you can refer to the above link.

你可以参考上面的链接。

I use the following code in my EntityController.

我在我的EntityController.

public async Task<IActionResult> LoadDataAsync([FromForm]JqueryDataTablesParameters parameters)
{
    var (data, filtered, total) = await GetAllAsync(parameters, "Id", "Code", "Name");

    //Returning Json Data  
    return Json(new JqueryDataTablesResult<GradeDto>
    {
        Draw = parameters.Draw,
        Data = data,
        FilteredRecords = filtered,
        TotalRecords = total
    });
}