How to use jQuery to paginate JSON data?

后端 未结 5 1193
迷失自我
迷失自我 2020-12-09 12:47

Duplicate:

Good jquery pagination plugin to use with json Data…

My JSON data looks like this



        
5条回答
  •  不思量自难忘°
    2020-12-09 13:30

    Simple way for JQuery JSON pagination demo https://jsfiddle.net/rijo/0kjow220/

    Html code

    Play Id Question1
    next
    Pre

    Script code

     $(document).ready(function(){
          var table =  $('#myTable');
    var b = [{"play_id":"1","question1":"135","q1r":"1","question2":"138","q2r":"1","question3":"","q3r":"0","question4":"","q4r":"0","total_point":"6","amount":"1.7","bet_amount":"10","winning_amount":"20","no_of_players":"10"},....]
        var max_size=b.length;
         var sta = 0;
         var elements_per_page = 4;
         var limit = elements_per_page;
         goFun(sta,limit);
         function goFun(sta,limit) {
          for (var i =sta ; i < limit; i++) {
    
            var $nr = $('A-' + b[i]['play_id'] + 'B-' + b[i]['question1']  + '');
            table.append($nr);
          }
          }
          $('#nextValue').click(function(){
    
            var next = limit;
            if(max_size>=next) {
            limit = limit+elements_per_page;
            table.empty();
            console.log(next +' -next- '+limit);
            goFun(next,limit);
            }
          });
          $('#PreeValue').click(function(){
            var pre = limit-(2*elements_per_page);
            if(pre>=0) {
            limit = limit-elements_per_page;
            console.log(pre +' -pre- '+limit);
            table.empty();
            goFun(pre,limit); 
            }
          });
    
        });
    

提交回复
热议问题