Join the Stack Overflow Community
Stack Overflow is a community of 6.6 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I would like to know how can i paginate a json array by using javascript? Here is the json array which i need to paginate. this is a small array but i have to paginate a big array which hold 2000 records.


    {"Type":[["TF_OTHER","Other"],["TF_TRIP","Trip"],["TF_LUNCH","Lunch"]]}

share|improve this question
    
Paginate how? – Bojangles Dec 24 '12 at 9:33
1  
How are you displaying the data? If you are displaying as a table, jQuery Datatables is a great plugin for this: datatables.net – John Farrelly Dec 24 '12 at 10:01

You can try something like this: (I didn't test it though)

<script>

var arr
function onLoad(jsonArr) {
    arr = eval(jsonArr);
}

function paginate(offset, max)
{
    var demo = document.getElementById('demo');
    for(var n=0; n<demo.childNodes.length; n++){
        demo.removeChild(demo.childNodes[0]);
    }

    for(var i=0; i<max; i++){
        var ele=document.createTextNode(arr[i+offset]);
        demo.appendChild(ele);
    }

    var next = document.getElementById('next');
    next.setAttribute("onclick","paginate("+(offset+max)+","+max+")");
    var pre = document.getElementById('pre');
    pre.setAttribute("onclick","paginate("+(offset-max)+","+max+")");
}

</script>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.