哪种分页方法对大量数据有效?

时间:2018-11-18 10:04:30

标签: javascript jquery asp.net asp.net-mvc pagination

我有一个表,其中包含超过200000个数据。我想要一个分页,可以更快地处理所有这些数据。我应该使用数据表进行分页,但是数据表几乎无法管理它。如果使用数据表,性能会慢很多。我的项目在ASP.NET MVC中。

当前,我正在使用此方法。它工作正常,但跟踪会话变得越来越困难!尤其是当我从任何页面更新某些内容时,它都会丢失会话并转到第一个页面!我已经为此使用了TempData,但是再次变得越来越复杂。我想实现一种简单的逻辑来管理这些数据以进行分页!

   <span class="page-info">
                Page @(SectionTypeList.PageCount < SectionTypeList.PageNumber ? 0 : SectionTypeList.PageNumber) of @SectionTypeList.PageCount
            </span>
            <span class="showing-info">
                Showing @SectionTypeList.FirstItemOnPage to @SectionTypeList.LastItemOnPage of @SectionTypeList.TotalItemCount Section
            </span>
            @Html.PagedListPager(SectionTypeList, page => Url.Action("GetSectionRecord", new { page, pageSize = SectionTypeList.PageSize, SearchBy = ViewBag.searchValue }))
        </div>

除了在特定页面中完成更新之外,此方法可以正常工作!因为在第3页(例如)更新后,它会转到第一页。

 public ActionResult GetSectionRecord(int page = 1, int pageSize = 10, string SearchBy = "")
    {
        SectionModel objSectionModel = new SectionModel();
        DepartmentLookUpModel objDepartmentLookUp = new DepartmentLookUpModel();

        if (Session["strEmployeeId"] == null)
        {
            return RedirectToAction("LogOut", "Login");
        }
        else
        {
            LoadSession();

            TempData["PageNumberFromSearch"] = page;
            if (!string.IsNullOrEmpty(SearchBy))
            {
                ViewBag.searchValue = SearchBy;
                TempData["SearchValueFromSearchAction"] = SearchBy;
                objSectionModel.SearchBy = SearchBy;
                TempData.Keep("SearchValueFromSearchAction");
                TempData["SearchActionFlag"] = "1";
                TempData.Keep("SearchActionFlag");
            }
            if (string.IsNullOrEmpty(SearchBy))
            {
                if (Convert.ToInt32(TempData["SearchActionFlag"]) == 1)
                {
                    if (Convert.ToInt32(TempData["SearchActionFlag"]) == 1 && Convert.ToInt32(TempData["UpdateFlag"]) == 1)
                    {
                        page = Convert.ToInt32(TempData["UpdatePageNumber"]);
                        TempData.Keep("UpdatePageNumber");
                        objSectionModel.SearchBy = TempData["SearchValueFromSearchAction"].ToString();
                        TempData.Keep("SearchValueFromSearchAction");

                    }
                    else
                    {
                        page = Convert.ToInt32(TempData["PageNumberFromSearch"]);
                        TempData.Keep("PageNumberFromSearch");
                        objSectionModel.SearchBy = TempData["SearchValueFromSearchAction"].ToString();
                        TempData.Keep("SearchValueFromSearchAction");
                    }

                    TempData.Keep("SearchActionFlag");
                }

                else if (Convert.ToInt32(TempData["EditActionFlag"]) == 1 && Convert.ToInt32(TempData["UpdateFlag"]) == 1)
                {
                    page = Convert.ToInt32(TempData["UpdatePageNumber"]);
                    TempData.Keep("UpdatePageNumber");

                }
                else
                {

                    if (Convert.ToInt32(TempData["SearchActionFlag"]) == 1)
                    {
                        objSectionModel.SearchBy = TempData["SearchValueFromSearchAction"].ToString();
                        TempData.Keep("SearchValueFromSearchAction");
                    }
                    else
                    {
                        objSectionModel.SearchBy = SearchBy;
                    }
                }

            }
            objSectionModel.UpdateBy = strEmployeeId;
            objSectionModel.HeadOfficeId = strHeadOfficeId;
            objSectionModel.BranchOfficeId = strBranchOfficeId;

            objDepartmentLookUp.UpdateBy = strEmployeeId;
            objDepartmentLookUp.HeadOfficeId = strHeadOfficeId;
            objDepartmentLookUp.BranchOfficeId = strBranchOfficeId;

            DataTable dt = objLookUpDAL.GetSectionRecord(objSectionModel);
            if (dt.Rows.Count <= 2)
            {
                page = 1;
            }
            var SectionTypeList = SectionTypeListData(dt);
            ViewBag.SectionTypeList = SectionTypeList.ToPagedList(page, pageSize);
            ViewBag.DepartmentDDList = UtilityClass.GetSelectListByDataTable(objLookUpDAL.GetDepartmendDDList(), "DEPARTMENT_ID", "DEPARTMENT_NAME");

            TempData["GetActionFlag"] = 1;
            return View(objSectionModel);
        }            
    }

你们能建议我哪种分页方法处理大量数据会更快?

0 个答案:

没有答案