0

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"]]}

1
  • 1
    How are you displaying the data? If you are displaying as a table, jQuery Datatables is a great plugin for this: datatables.net Commented Dec 24, 2012 at 10:01

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.