1

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...

Kassem
  • 8,116
  • 17
  • 75
  • 116
  • What do you mean by displaying more than one element? By this I understand as the number of items per page, but this plugin already have this option, and you use it... Can you put an example in a fiddle? – Ortiga May 17 '11 at 09:42
  • @Andre: The problem is that the plugin uses that option internally for rendering the pagination widget only. It doesn't really use this as the number of items actually displayed in the result div. – Kassem May 17 '11 at 09:44
  • Yes, it does. You can see it working in the oficial demo: http://d-scribe.de/webtools/jquery-pagination/demo/demo_options.htm . – Ortiga May 17 '11 at 09:50
  • @Andre: No, look at the source code. You'll see that the author is retrieving the number of items to be displayed from the value of the text box. – Kassem May 17 '11 at 09:54

0 Answers0