使用jquery数据表。为什么分页不起作用?

问题描述 投票:0回答:1

它还显示所有记录,而不是例如“14 条中的 14 条中的 11 条”。我如何进行通信以一次仅发送 10 条?我用这篇文章作为教程

http://www.codeproject.com/Articles/155422/jQuery-DataTables-and-ASP-NET-MVC-Integration-Part

    public ActionResult GetCurrentErrorsAJAX(JQueryDataTableParamModel param)
    {
        List<StepInstanceError> allCompanies = new List<StepInstanceError>();
        allCompanies = InstanceErrorExpert.GetAllErrors();

        IEnumerable<StepInstanceError> filteredCompanies;
        filteredCompanies = allCompanies;

        var sortColumnIndex = Convert.ToInt32(Request["iSortCol_0"]);
        Func<StepInstanceError, string> orderingFunction = (c => sortColumnIndex == 1 ? c.FilePath :
                                                            sortColumnIndex == 2 ? c.Notes :
                                                            c.Notes);

        var sortDirection = Request["sSortDir_0"]; // asc or desc
        if (sortDirection == "asc")
            filteredCompanies = filteredCompanies.OrderBy(item => orderingFunction);
        else
            filteredCompanies = filteredCompanies.OrderByDescending(item => orderingFunction);

        var displayedCompanies = filteredCompanies;

        var result = from c in displayedCompanies
                     select new[] { Convert.ToString(c.StepInstanceErrorID),
                                    Convert.ToString(c.StepInstanceID),
                                    Convert.ToString(c.ErrorRow),
                                    Convert.ToString(c.Notes),
                                    c.FilePath,
                                    c.Notes,
                                    Convert.ToString(c.DateCreated)
        };

        return Json(new
        {
            sEcho = param.sEcho,
            iTotalRecords = allCompanies.Count(),
            iTotalDisplayRecords = filteredCompanies.Count(),
            aaData = result
        },
                    JsonRequestBehavior.AllowGet);
    }

<script>
$(function () {
    var RefreshErrorTable = function () {
        var oTable = $('#myDataTable').dataTable({
            "bServerSide": true,
            "sAjaxSource": "Errors/GetCurrentErrorsAJAX",
            "bProcessing": true,
            "aoColumns": [
                            { "sName": "StepInstanceID" },
                            { "sName": "ErrorRow" },
                            { "sName": "FilePath" },
                            { "sName": "Notes" },
                            { "sName": "DateCreated" }
            ]
        });
    }

    RefreshErrorTable();
});

jquery datatables pagination
1个回答
2
投票

对于服务器端处理,DataTables 还传递

iDisplayStart
iDisplayLength

您的查询应包含此内容以限制返回的行数。 您的示例页面显示了这一点:

var displayedCompanies = filteredCompanies
                        .Skip(param.iDisplayStart)
                        .Take(param.iDisplayLength); 

默认情况下应启用数据表中的分页(bPaginate)。 DataTables 网站非常棒,可能会有所帮助:http://www.datatables.net/usage/features

© www.soinside.com 2019 - 2024. All rights reserved.