Take the 2-minute tour ×

So, my problem was the following. It's follow the previous HERE & HERE

I got dynamycaly added table from XML with this code:

    type: "GET",
    url: "../datas/_pizzas",
    dataType: "xml",
    success: function(xml) {
        $(xml).find('row').each(function() {
            var getNom = $(this).find('nomp').text();
            var Prix1 = $(this).find('petit').text();
            var Prix2 = $(this).find('moyen').text();
            var Prix3 = $(this).find('grand').text();
            $('<table id="item"></table>').html('<tr><td id="test" onclick="afficher(\''+getNom +'\','+Prix1+','+Prix2+','+Prix3+');"><b>' + getNom + '</b></td></tr>').appendTo('#pizzas');

and i need to limit the number of them on the page. And if possible have a index navigation. I search for a pagination plugin that would do the trick but I have not found any that suited me, too much useless config, or unreadable for me.

Someone have code or explain for me ????

share|improve this question

closed as not a real question by Sparky, bensiu, Mario, user97693321, Explosion Pills Dec 1 '12 at 20:17


Typically, even when you intend on posting an answer yourself, you'd post a clearly written and detailed question. Then you'd give others plenty of time to post answers before posting your own. Otherwise now, it's much less likely anyone would answer since they assume you'll be accepting your own. –  Sparky Nov 30 '12 at 23:34
"To be crystal clear, it is not merely OK to ask and answer your own question, it is explicitly encouraged." –  bZezzz Nov 30 '12 at 23:47
My question was that... How can I be more clear ? –  bZezzz Nov 30 '12 at 23:48
Of course it's OK! I'm not saying otherwise. I'm merely telling you that waiting a bit before answering, gets more answers. More answers => better SO website. As far as the quality of your question... it's of the type that gets closed quickly. –  Sparky Nov 30 '12 at 23:50
Why when you ask a question then ask you if you want to answer directly... So... We dont care –  bZezzz Nov 30 '12 at 23:58
show 1 more comment

1 Answer

Working demo


//For Stackoverflow Community
//Fork Fork Fork Fork !
item = $('table'); //Any element you want
itemL = item.length; //Get the Item count
itNbr = 5; //Set the Item per page
pgNbr = 0; //Set the page count to 0

//Hide unwanted row
function start() {
    if (itemL > itNbr) { //If Items Count greater than Item per page
        item.hide(); //Hide All Items
        item.slice(0, itNbr).show(); //Show only the 0 to 'X'. X = Item per page
        pgNbr = Math.ceil(itemL / itNbr); //Get the page Number Item Count / Item per Page round to Greater
        thisPage = 1; //Set the Start Page

//Get the pages Index
function indexer() {
    $('textarea').val(thisPage + ' / ' + pgNbr); //Sipmply set val.
//Bind the action
$('.pager').click(function() {
    //Create loop
    if (thisPage == pgNbr) { //If last page 
        start(); //Go 1st
        indexer(); //Get Index
    else {
        var first = itNbr * thisPage; //Define the first visible item 'X'
        var last = (itNbr * thisPage) + itNbr; //Define the last visible item 'Y'
        item.hide(); //Hide All
        item.slice(first, last).show(); //Show only 'X' to 'Y'
        thisPage++; //Increment page number
        indexer(); //And get the index


//Let's GO !
share|improve this answer
add comment
