Infinite scroll jquery plugin in codeigniter

前端 未结 2 1645
感情败类
感情败类 2021-01-03 16:41

I have a pagination.php file in the config folder. the code is below

$config[\'num_links\'] = 5;
$config[\'use_page_numbers\'] = TRUE;
$config[\'query_string         


        
2条回答
  •  清歌不尽
    2021-01-03 17:39

    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 += '';
                html += '';
                html += ''+ json[i].id +'';
                html += '';
                html += ' ' + json[i].firstname +'';
                html += ' ' + json[i].middlename +'';
                html += ' ' + json[i].lastname +'';
                html += ' ' + json[i].address +'';
                html += ' ' + json[i].mobile +'';
                html += ' ' + json[i].email +'';
                html += ' ' + json[i].gender +'';
                html += 'Delete';
                html += 'Update';
                html += '';
            }$("#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();
    }    
    

提交回复
热议问题