开发者

jQuery Pagination Display More Than One Element

I'm trying to use the Pagination Plugin to paginate some item search results. Unfortunately, the demos and documentation aren't very clear when it comes to displaying more than one result. At least that's what I felt...

So anyway, it seems that I need to write my own Skip and Take code inside the callback function in order to get the result I need. Here's what I've got so far:

function setupPagination(num_items) {
    var num_entries = $('#hiddenItemsContainer div.indexItem').length;
    // Create pagination element
    $("#paginationWidget").pagination(num_entries, {
        current_page: 0,
        items_per_page: num_items,
        num_display_entries: 5,
        next_text: 'Next',
        prev_text: 'Prev',
        callback: pageselectCallback,
        num_edge_entries: 1
    }); 
}

function pageselectCallback(page_index, jq){
    var num_entries = $('#hiddenItemsContainer div.indexItem').length;
    var items_per_page = $('#ItemsPerPage').val();
    var newcontent = ($('#hiddenItemsContainer div.indexItem').slice(Math.min((page_index+1) * items_per_page), items_per_page)).clone();
    console.log(newcontent);

    // Replace old content with new content
    $('#itemsContainer').empty().html(newcontent);

    return false;
}
开发者_如何学运维

I keep getting an empty array as the value of newContent. So it has to be something wrong with the way I'm using the slice function.

Any thoughts?

UPDATE:

Problem solved. I finally figured it out! Here's the solution:

function pageselectCallback(page_index, jq){
    console.log(page_index);
    var num_entries = $('#hiddenItemsContainer div.indexItem').length;
    var items_per_page = $('#ItemsPerPage').val();
    var newcontent = ($('#hiddenItemsContainer div.indexItem').slice(Math.min(page_index * items_per_page), ((page_index + 1) * items_per_page))).clone();
    console.log(newcontent);

    // Replace old content with new content
    $('#itemsContainer').html(newcontent);

    return false;
}

But one more thing... Is there a way to pass the items_per_page value to the callback function? It doesn't make sense that I have to save it in a hidden field just so I could access it...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜