EasyUI datagrid url not fetching data from table

my model

<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
class User_model extends CI_Model{

  public function get_user($offset,$limit,$q=''){

    $sql = "SELECT * FROM users WHERE 1=1 ";
    if($q!=''){

        $sql .=" AND name LIKE '%{$q}%' ";
    }
    $result['count'] = $this->db->query($sql)->num_rows();
    $sql .=" LIMIT {$offset},{$limit} ";
    $result['data'] = $this->db->query($sql)->result();

    return $result ;
}

}

<?php

class User extends CI_Controller{

public function __construct(){

    parent::__construct();

    //load the model
   // $this->load->model('user_model'); 
}

//load user view
public function index(){


    $this->load->view('user_view');
}

//get data for datagrid
public function get_user(){

    /*Default request pager params dari jeasyUI*/
    $offset = isset($_POST['page']) ? intval($_POST['page']) : 1;
    $limit  = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
    $search = isset($_POST['search']) ? $_POST['search'] : '';
    $offset = ($offset-1)*$limit;
    $data   = $this->user_model->get_user($offset,$limit,$search);
    $i  = 0;
    $rows   = array(); 
    foreach ($data ['data'] as $r) {

       //array keys ini = attribute 'field' di view nya
       $rows[$i]['first_name'] = $r->first_name;
       $rows[$i]['last_name'] = $r->last_name;
       $rows[$i]['phone'] = $r->phone;
       $rows[$i]['email'] = $r->email;

     $i++;
    }

    //keys total & rows wajib bagi jEasyUI
    $result = array('total'=>$data['count'],'rows'=>$rows);
    echo json_encode($result); //return nya json
}

}


  <?php $url_data=base_url().'user/get_user';?>
      <?php echo $url_data;?>


<table id="dg" title="Product" class="easyui-datagrid" 
style ="width:auto;height:400px"
url   ='<?php echo $url_data;?>' toolbar="#toolbar" 
pagination="true" 
rownumbers="false" 
fitColumns="true" singleSelect="true" 
checkBox  ="true" striped="true" 
remoteSort="false" 
nowrap    ="false">
     <thead>
        <tr>
	   <th field="ck" checkbox="true"></th> 
	   <th field="first_name" width="200"  sortable="true">
             <b>First Name</b>
           </th>
	   <th field="last_name" width="700" sortable="true">
           <b>Last Name</b>
          </th>
         <th field="phone" width="100" sortable="true">
          <b>Phone</b>
         </th>
         <th field="email" width="100" sortable="true">
          <b>email</b>
         </th>		
	</tr>
     </thead>
</table>

I’m a bit puzzled - is there a question to go with your code?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.