Jqgrid分页由于查询而无法工作


Jqgrid Pagination not working due to query

我正在尝试建立一个jqgrid,但我在构建生成json数据以填充网格的控制器时遇到了困难。我使用的是codeigniter 2.0+,我不知道如何在codeignite器中为php构建查询。

我在jqgrid的"Loading Data->JSON Data"下遵循了这个指南。我还查阅了关于数据选择的codeigniter文档。问题是我不知道如何编写第二个查询来根据jqgrid参数进行排序和限制。这是我的控制器。

public function applicantdata(){
    $page = $this->input->get('page');// get the requested page
    $limit = $this->input->get('rows');// get how many rows we want to have into the grid
    $sidx = $this->input->get('sidx');// get index row - i.e. user click to sort
    $sord = $this->input->get('sord');// get the direction
    if(!$sidx){ $sidx =1; }
     $this->db->select('*');
     $this->db->from('applicant');
     $this->db->join('transaction', 'transaction.applicant_id = applicant.id');
     $query = $this->db->get();    
     $count = $query->num_rows();
     $limit = 10;         
        if( $count > 0 ) {
            $total_pages = ceil($count/$limit);
        } else {
            $total_pages = 0;
        }        
        if ($page > $total_pages){ $page=$total_pages; }        
        $start = $limit*$page - $limit; // do not put $limit*($page - 1)
//NOT SURE HOW TO DO THIS IN CODEIGNITER ENVIRONMENT
//$SQL = "SELECT a.id, a.invdate, b.name, a.amount,a.tax,a.total,a.note FROM invheader a, clients b WHERE a.client_id=b.client_id ORDER BY $sidx $sord LIMIT $start , $limit";
//$result = mysql_query( $SQL ) or die("Couldn t execute query.".mysql_error());   

        $result = $query->result_array(); 
        $responce->page = $page;
        $responce->total = $total_pages;
        $responce->records = $count;
        $i=0;            
        foreach ($result as $myrow){
            $responce->rows[$i]['id']=$myrow['id'];
            $responce->rows[$i]['cell']=array($myrow['id'],$myrow['firstname'],$myrow['lastname'],$myrow['amount'],$myrow['status']);
            $i++;
         }       
    echo json_encode($responce);
}

通过上面的代码,网格正在填充,并且它正在更大程度上工作。唯一的问题是分页的东西不能正常工作,因为当我移动到第2页、第3页等时,第一页上的数据会显示出来。

她是最后的工作对象。对于任何可能需要它的人。

public function applicantdata(){
    $page = $this->input->get('page');// get the requested page
    $limit = $this->input->get('rows');// get how many rows we want to have into the grid
    $sidx = $this->input->get('sidx');// get index row - i.e. user click to sort
    $sord = $this->input->get('sord');// get the direction
    if(!$sidx){ $sidx =1; }
     $this->db->select('firstname');
     $this->db->from('applicant');
     $this->db->join('transaction', 'transaction.applicant_id = applicant.id');
     $query = $this->db->get();    
     $count = $query->num_rows();
        if( $count > 0 ) {
            $total_pages = ceil($count/$limit);
        } else {
            $total_pages = 0;
        }        
        if ($page > $total_pages){ $page=$total_pages; }        
        $start = $limit*$page - $limit; // do not put $limit*($page - 1)

        $this->db->select('*');
        $this->db->from('applicant');
        $this->db->join('transaction', 'transaction.applicant_id = applicant.id');
        $this->db->order_by("applicant.id", $sord);
        $this->db->limit($limit, $start);
        $query2 = $this->db->get();               
        $result = $query2->result_array(); 
        $responce->page = $page;
        $responce->total = $total_pages;
        $responce->records = $count;
        $i=0;            
        foreach ($result as $myrow){
            $responce->rows[$i]['id']=$myrow['id'];
            $responce->rows[$i]['cell']=array($myrow['id'],$myrow['firstname'],$myrow['lastname'],$myrow['amount'],$myrow['status']);
            $i++;
         }       
    echo json_encode($responce);
}