EllisLab text mark
Advanced Search
     
[Help]not appear jqgrid data in codeigniter
Posted: 29 September 2012 10:46 AM   [ Ignore ]
Joined: 2012-09-29
1 posts

i have a code for showing data at jqgrid with codeigniter..i can show a table jqgrid but the data dont showed..maybe the master can help me..
This Model

<? if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class 
M_admininfokes extends CI_Model {
 
function __construct() {
        parent
::__construct();
    
}
 

 
function getAll(){
    $this
->db->select('kode_puskesmas,nama,alamat,kode_kelurahan');
    
$this->db->from('tbl_puskesmas');
    
$this->db->limit(10);
    
$this->db->order_by('kode_puskesmas','ASC');
    
$query $this->db->get();

    return 
$query->result();
  
}

  
function getAllGrid($start,$limit,$sidx,$sord,$where){
    $this
->db->select('kode_puskesmas,nama,alamat,kode_kelurahan');
    
$this->db->limit($limit);
    if(
$where != NULL)$this->db->where($where,NULL,FALSE);
    
$this->db->order_by($sidx,$sord);
    
$query $this->db->get('tbl_puskesmas',$limit,$start);

    return 
$query->result();
  
}

  
function get($kode_puskesmas){
    $query 
$this->db->getwhere('tbl_puskesmas',array('kode_puskesmas'=>$kode_puskesmas));
    return 
$query->row_array();
  
}

     
  }
    
    
?> 


The Controller

<? if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class 
C_admininfokes extends CI_Controller{
 
function __construct()
 
{
  session_start
();
  
parent::__construct();
  
$this->load->model('m_admininfokes','m_adm'); 
  
$this->load->library('tree');
  
$this->load->model('p_c_model');
     if ( !isset(
$_SESSION['nik']) ) {
         redirect
('c_login');
      
}
 }
 
 
 
public function index(){
  
  $this
->load->view('infokes/v_home');
  
 
}
 
 
 
public function masterdata(){
  $this
->grid();
 
}
 
 
public function grid(){
  $this
->load->view('infokes/v_master_data_admin');
 
}
 
 
function json() {
  $page 
= isset($_POST['page'])?$_POST['page']:1// get the requested page
  
$limit = isset($_POST['rows'])?$_POST['rows']:10// get how many rows we want to have into the grid
  
$sidx = isset($_POST['sidx'])?$_POST['sidx']:'kode_puskesmas'// get index row - i.e. user click to sort
  
$sord = isset($_POST['sord'])?$_POST['sord']:''// get the direction

        
$start $limit*$page $limit// do not put $limit*($page - 1)
  
$start = ($start<0)?0:$start;  // make sure that $start is not a negative value

  
$where ""//if there is no search request sent by jqgrid, $where should be empty
        
$searchField = isset($_POST['searchField']) ? $_POST['searchField'false;
        
$searchOper = isset($_POST['searchOper']) ? $_POST['searchOper']false;
        
$searchString = isset($_POST['searchString']) ? $_POST['searchString'false;

        if (
$_POST['_search'== 'true'{
            $ops 
= array(
            
'eq'=>'='//equal
            
'ne'=>'<>',//not equal
            
'lt'=>'<'//less than
            
'le'=>'<=',//less than or equal
            
'gt'=>'>'//greater than
            
'ge'=>'>=',//greater than or equal
            
'bw'=>'LIKE'//begins with
            
'bn'=>'NOT LIKE'//doesn't begin with
            
'in'=>'LIKE'//is in
            
'ni'=>'NOT LIKE'//is not in
            
'ew'=>'LIKE'//ends with
            
'en'=>'NOT LIKE'//doesn't end with
            
'cn'=>'LIKE'// contains
            
'nc'=>'NOT LIKE'  //doesn't contain
            
);

            foreach (
$ops as $key=>$value){
                
if ($searchOper==$key{
                    $ops 
$value;
                
}
            }
            
if($searchOper == 'eq' $searchString $searchString;
            if(
$searchOper == 'bw' || $searchOper == 'bn'$searchString .= '%';
            if(
$searchOper == 'ew' || $searchOper == 'en' $searchString '%'.$searchString;
            if(
$searchOper == 'cn' || $searchOper == 'nc' || $searchOper == 'in' || $searchOper == 'ni'$searchString '%'.$searchString.'%';

            
$where "$searchField $ops '$searchString' ";
        
}

  
if(!$sidx$sidx =1;
        
$count $this->db->count_all_results('tbl_puskesmas');

  if( 
$count {
   $total_pages 
ceil($count/$limit);    //calculating total number of pages
  
else {
   $total_pages 
0;
  
}

  
if ($page $total_pages$page=$total_pages;
     
$query $this->m_adm->getAllGrid($start,$limit,$sidx,$sord,$where);

  
$responce->page $page;
  
$responce->total $total_pages;
  
$responce->records $count;
  
$i=0;
  foreach(
$query as $row{
   $responce
->rows[$i]['kode_puskesmas']=$row->kode_puskesmas;
   
$responce->rows[$i]['cell']=array($row->kode_puskesmas,$row->nama,$row->alamat,$row->kode_kelurahan);
   
$i++;
  
}
  
echo json_encode($responce);
 
}
}

?> 

The view

[removed]
   jQuery
().ready(function (){
    jQuery
("#list1").jqGrid({
        url
:'<? echo base_url();?>index.php/c_admininfokes/json',      //another controller function for generating data
     
mtype "post",             //Ajax request type. It also could be GET
     
datatype"json",            //supported formats XML, JSON or Arrray
        
colNames:['Kode Puskesmas','Nama','Alamat','Kelurahan'],       //Grid column headings
        
colModel:[
         {name
:'kode_puskesmas',index:'kode_puskesmas'width:30align:"left"},
         
{name:'nama',index:'nama'width:20align:"left"},
         
{name:'alamat',index:'alamat'width:20align:"left"},
         
{name:'kode_kelurahan',index:'kode_kelurahan'width:20align:"right"},
       
],
        
rowNum:10,
        
width450,
     
height300,
        
rowList:[10,20,30],
        
pager'#pager1',
        
sortname'kode_puskesmas',
        
viewrecordstrue,
     
rownumberstrue,
     
gridviewtrue,
     
caption:"Puskesmas"
    
}).navGrid('#pager1',{edit:false,add:false,del:false});
   
});
  
[removed]
  
<table id="list1"></table> <!--Grid table-->
  <
div id="pager1"></div>  <!--pagination div-->