简体   繁体   English

HTML 和 Javascript 搜索结果分页 - 限制显示的结果页面数量

[英]HTML and Javascript search result pagination - limit the number of result pages showing

Using HTML and javascript I have some basic search result pagination which, although works, if there are hundreds of results, I can end up with pagination looking like this:使用 HTML 和 javascript 我有一些基本的搜索结果分页,虽然有效,但如果有数百个结果,我最终可以得到如下所示的分页:

在此处输入图片说明

I would like to limit this to show only 1 - 10, then 11 - 10 etc, can anyone direct me to an example of how to do this?我想将其限制为仅显示 1 - 10,然后是 11 - 10 等,任何人都可以指导我如何执行此操作的示例吗?

<div class="row igs-learning-paths-pagination-row">
                <div class="col-12 d-flex justify-content-center" >
                    <ul class="pagination pagination-info">
                        <li class="page-item">
                            <a href="javascript:void(0)" onclick="displayPreviousPage()" class="igs-learning-paths-pagingation-text igs-text-uppercase">
                                @Umbraco.GetDictionaryValue("Common Prev", "Prev..").ToUpper()
                            </a>
                        </li> &nbsp;


                        @for (int i = 0; i <= @Model.Results.Count() / numberPerPage; i++)
                        {
                            <li class="@(i == 0 ? "active" : null) page-item non-generate-page-item" id="page-list-item-@(i)" style="border-radius:16px;">
                                <a class="page-link" id="page-number-@(i)" href="javascript:void(0)" onclick="displayPages(@(i))">@(i + 1)</a>
                            </li>
                        }

                        <li class="page-item" alt="Go forward a page" title="Go forward a page">
                            <a href="javascript:void(0)" alt="Go forward a page" title="Go forward a page"
                               onclick="displayNextPage()"
                               class="igs-learning-paths-pagingation-text igs-text-uppercase search-result-margin">
                                @Current.UmbracoHelper.GetDictionaryValue("Common Next", "Next..").ToUpper()
                            </a>
                        </li>
                    </ul>
                </div>

            </div>


<script>
var numberPerPage = @numberPerPage;
var totalResults = @Model.Results.Count();
var maxPage = Math.floor(totalResults / numberPerPage);
var currentPage = 0;
var previousPage = 0;

function displayNextPage() {
    if (currentPage == maxPage) return;

    currentPage = currentPage + 1
    displayPages(currentPage);
}

function displayPreviousPage() {
    if (currentPage == 0) return;

    currentPage = currentPage - 1
    displayPages(currentPage);
}

function displayPages(pageToDisplay) {
    $(".page-search-hider").hide();
    currentPage = pageToDisplay;
    if (!pageToDisplay) {
        pageToDisplay = 0
    }
    else {
        var skip = pageToDisplay * numberPerPage;
        pageToDisplay = skip+1;
    }

    var newNumberPerPage = numberPerPage;

    document.getElementById("page-list-item-" + previousPage).classList.remove("active")
    previousPage = currentPage;
    document.getElementById("page-list-item-" + currentPage).classList.add("active")

    for (var i = 0; i <= newNumberPerPage; i++) {
        var result = pageToDisplay + i;
        $("#pageId-" + result).show();
        $("#pageId-" + @(pageIdCount)).hide();
    }
}

 const pageNumbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; const maxPageLimit = 5; let upperPageIndex = maxPageLimit; let currentPageIndex = 0; let displayPages = pageNumbers.slice(currentPageIndex , upperPageIndex); // slice(startIndex, endIndex); console.log(displayPages) // if currentPageIndex = 2 then show 2 more as you go through upperPageIndex += 2; // You can make 2 a constant if needed currentPageIndex += 2; displayPages = pageNumbers.slice(currentPageIndex , upperPageIndex); console.log(displayPages)

REF: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice参考资料: https : //developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM