2012-06-07 117 views
3

我一直在試圖添加無限滾動codeigniter的這個插件的分頁。添加無限滾動到codeigniter分頁

http://www.infinite-scroll.com 

這是我的代碼至今:

<script type = "text/javascript"> 

    $('#comments').infinitescroll({ 

     navSelector : "a#next:last", // selector for the paged navigation (it will be hidden) 
     nextSelector : "a#next:last", // selector for the NEXT link (to page 2) 
        itemSelector : "#comments"  // selector for all items you'll retrieve 
       }); 

</script> 

這是默認的使用。讓我們假設#評論保留我的內容。我的分頁頁面看起來像這樣。

http://localhost/ci/index.php/chat/load/p1u/10 
http://localhost/ci/index.php/chat/load/p1u/20 

我甚至已經添加這行代碼,使其工作,但沒有成功:

<a id="next" href="http://localhost/ci/index.php/chat/load/p1u/10">next page</a> 

任何想法?

+1

我找到了解決方法。我使用jquery來確定何時到達滾動div的末尾,並將load/p1u/10中的內容附加到html中。由於下一頁顯然是/ 20/30等等,我保留了一個全局變量,每次增加10,當窗口結束時。這工作正常,內容適當顯示。 –

回答

1

如果要使用/ 1/2/3而不是/ 10/20/30,請在pagination.php中切換爲使用$config["use_page_numbers"]

1

我發現這肯定用$ config [「use_page_numbers」] = TRUE更好;但如果你要走這條路線,你必須調整你的偏移量。這是我如何得到它的工作:

$offset = ($this->uri->segment(2)) ? ($this->uri->segment(2) * $config["per_page"]) - $config["per_page"] : 0; 
0

我對代碼點火器滾動分頁簡單的一步, 我已經檢查了這更好地工作

$(window).scroll(function(){ 
    if ($(window).scrollTop() == $(document).height() - $(window).height()){ 
     // run our call for pagination 
     var table = document.getElementById("table"); 
     var lastRowIndex = table.rows.length-1; 
     loadMore(lastRowIndex); 
    } 
}); 

function loadMore(lastRowIndex) 
{ 
$.ajax({ 
    url: "http://localhost/CodeIgniter/index.php/form/loadmore", //form is y controller 
    type:'POST', 
    data: "row="+lastRowIndex, // row wich is post 
    success: function(data){ //here data which recevie form controller 
     var json = JSON.parse(data); 
     var count = json.length; 
     var html; 
     for(var i = 0; i < count; i++) 
     { 
      html += '<tr>'; 
      html += '<td><input type="checkbox" name="id[]" id="id[]" class="check" value="'+ json[i].id +' "></td>'; 
      html += '<td>'+ json[i].id +'</td>'; 
      html += '<td><img src="http://localhost/CodeIgniter/upload/'+ json[i].image +'" class="img-circle" height="25" width="30"></td>'; 
      html += '<td> ' + json[i].firstname +'</td>'; 
      html += '<td> ' + json[i].middlename +'</td>'; 
      html += '<td> ' + json[i].lastname +'</td>'; 
      html += '<td> ' + json[i].address +'</td>'; 
      html += '<td> ' + json[i].mobile +'</td>'; 
      html += '<td> ' + json[i].email +'</td>'; 
      html += '<td> ' + json[i].gender +'</td>'; 
      html += '<td><a href="http://localhost/CodeIgniter/index.php/form/del/'+ json[i].id +'">Delete</a></td>'; 
      html += '<td><a href="http://localhost/CodeIgniter/index.php/form/edite/'+ json[i].id +'">Update</a></td>'; 
      html += '</tr>'; 
     }$("#body").append(html); //add this html to th table body which id='body' 
    } 
}); 
} 

我用這個控制器功能

public function loadmore() 
{ 
    $page=$_POST['row']; 
    $per_page = 10; 
    $student = $this->Form_model->getview_detail($per_page,$page); 
    if($student !== FALSE) 
    { 
     echo json_encode($student); //send data to script 
    } 
} 

`

,這是模型

public function getview_detail($limit, $start) 
{ 
    $this->db->limit($limit, $start); 
    $query = $this->db->get('form'); 
    return $query->result_array(); 
}