3

How can you modify a Codeigniter default pagination to follow

----viewMore--- link style when loading for more record - AJAX way.

The thing is how do you make the div so auto expanding that like you handle a 10,000 record at a time.

Develop4Life
  • 7,581
  • 8
  • 58
  • 76
user4650021
  • 61
  • 1
  • 7
  • 2
    You are asking about multiple different layers .... events in the UI, making ajax request , processing request at server and doing something with response. Which parts don't you understand? You need to narrow this down to specifics. If the answer to the above is "all" there are lots of ajax tutorials available – charlietfl Jul 22 '15 at 03:31
  • listen to charlietfl! I only add one thing between `processing the request` and `doing something with the response`: choose data format. I believe in your situation you should opt for JSON. – Adib Aroui Jul 22 '15 at 03:35
  • Similar to facebook, i want to implement. While clicking view more , some comments showing a limit, then one more click some more comments loading to the particular post. Like that way how to implement – user4650021 Jul 22 '15 at 03:36

2 Answers2

3

Try this

Make two Hidden Input in view

<button type="button" onclick="loadmore()" value="loadmore" >Load More</button>
<input type="hidden" name="limit" id="limit" value="10"/>
<input type="hidden" name="offset" id="offset" value="20"/>

Ajax call

function loadmore(){
    $.ajax({
        url:your_controller/loadmore,
        data:{
          offset :$('#offset').val(),
          limit :$('#limit').val()
        },
        type:json, 
        success :function(data){
            $('#load-more').prepend(data.view)
            $('#offset').val(data.offset)
            $('#limit').val(data.limit)
        }
    })
}

In your controller call model

 function loadmore(){
      $limit = $this->input->get('limit');
      $offset = $this->input->get('offset');
      $this->load->model('yourmodel');
      $result  = $this->yourmodel->getdata($offset,$limit);
      $data['view'] = $result;
      $data['offset'] =$offset +10;
      $data['limit'] =$limit;
      echo json_encode($data);
    }

write query in model with offset and limit

Community
  • 1
  • 1
shafiq.rst
  • 1,286
  • 1
  • 12
  • 26
1

You could use something like:

Example1

This is in core php, but you can understand the data flow and can make it then for MVC)

Also you can check this
Example

(Replace scroll event with button clicks)

Community
  • 1
  • 1
jones
  • 749
  • 7
  • 34