Reset total pages in jquery pagination plugin

后端 未结 5 523
你的背包
你的背包 2021-02-04 05:42

I am using TwbsPagination plug in for displaying paging in my app. It is working fine when we set the page size while initializing. However, based on the search result, I want t

5条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-04 06:10

    destroy method not worked for me(1.4.1), by look into the source code i find that there are 2 key point to make it re-instantiate correctly.

    1. pagination.data('twbs-pagination.js',null);
    2. the instantiate parameter startPage must be int type not String type

    above shows part of my code, hope it helps you:

    $('.unstyled > li >a').on('click', function (e) {
                e.preventDefault();
                pagination.data('twbs-pagination.js',null);
                loadPage(1,$(e.target).attr('categoryId'));
            });
    
    function initilizePagination(totalPages,currentPage,blogCategory){
                    pagination.twbsPagination({
                        initiateStartPageClick: false, 
                        totalPages: totalPages,
                        startPage: currentPage,
                        onPageClick: function (event, page) {
                            loadPage(page, blogCategory);
                        }
                    });
                    pagination.twbsPagination({render:currentPage});
                }
    
    function loadPage(page,blogCategory) {
                        $.ajax("url",
                            {
                                method: "get",
                                success: function (data) {
                                    $("#blogListWrapper").html(data);
                                    var ajaxPageCount = $('#ajaxPageCount').val();
                                    var ajaxPageNo = parseInt($('#ajaxPageNo').val());
                                 initilizePagination(ajaxPageCount,ajaxPageNo,blogCategory);
                                }
                            }
                        );
                    }
    

提交回复
热议问题