3

I have been trying to add infinite scrolling to codeigniter's pagination with this plugin.

http://www.infinite-scroll.com

This is my codes so far:

<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>

This is the default usage. Let us assume #comments hold my content. My paginated page looks something like these.

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

etc.

I have even added this line of code to make it work but with no success:

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

Any ideas?

1
  • 1
    I found a workaround. I used jquery to determine when i reached the end of the scroll div and append the content from load/p1u/10 to the html. Since the next page will obviously be /20 /30 and so on, i kept a global variable that increments each time by 10, when the end of the window is reached. This works fine and the content is displayed appropriately. Commented Jun 11, 2012 at 20:14

3 Answers 3

1

Switch to using $config["use_page_numbers"] in pagination.php if you want to use /1 /2 /3 instead of /10 /20 /30.

Sign up to request clarification or add additional context in comments.

Comments

1

I've found that this definitely works better with $config["use_page_numbers"] = TRUE; but if you're going to go that route, you'll have to adjust your offset. This is how I got it working:

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

Comments

0

i have simple step for the scrolling pagination in code igniter, i have check this it work better

$(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'
    }   
});
}

i use this controller function

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

`

and this is model

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

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.