Welcome Guest, Not a member yet? Register   Sign In
jqgrid with codeigneter
#1

[eluser]djupond[/eluser]
hi i have a problem of inmlepement jqgrid
my model
Code:
class ClientModel extends CI_Model{
       function getAllData($start,$limit,$sidx,$sord,$where){
        $this->db->select('clientId,nomC,emailC,passwordC,prenomC,favorisCl,favorisPh');

    $this->db->limit($limit);
    if($where != NULL)
        $this->db->where($where,NULL,FALSE);
    $this->db->order_by($sidx,$sord);
    $query = $this->db->get('client',$limit,$start);

    return $query->result();
}
}
my controller
Code:
class Home extends CI_Controller {



    function __construct()
{
  parent::__construct();
    
            $this->load->model('clientModel');

  
  
}
public function index()
{}

function jqGrid(){
$this->load->view('admin/homev');
}

function loadData(){
    $page = isset($_POST['page'])?$_POST['page']:1;
    $limit = isset($_POST['rows'])?$_POST['rows']:10;
    $sidx = isset($_POST['sidx'])?$_POST['sidx']:'clientId';
    $sord = isset($_POST['sord'])?$_POST['sord']:'';        
    $start = $limit*$page - $limit;
    $start = ($start<0)?0:$start;

    $where = "";
    $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'=>'=',
        'ne'=>'<>',
        'lt'=>'<',
        'le'=>'<=',
        'gt'=>'>',
        'ge'=>'>=',
        'bw'=>'LIKE',
        'bn'=>'NOT LIKE',
        'in'=>'LIKE',
        'ni'=>'NOT LIKE',
        'ew'=>'LIKE',
        'en'=>'NOT LIKE',
        'cn'=>'LIKE',
        'nc'=>'NOT LIKE'
        );
        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('client');
    if( $count > 0 ) {
        $total_pages = ceil($count/$limit);    
    } else {
        $total_pages = 0;
    }

    if ($page > $total_pages)
        $page=$total_pages;
    $query = $this->clientModel->getAllData($start,$limit,$sidx,$sord,$where);
    $responce->page = $page;
    $responce->total = $total_pages;
    $responce->records = $count;
    $i=0;
    foreach($query as $row) {
        $responce->rows[$i]['id']=$row->clientId;
        $responce->rows[$i]['cell']=array($row->nomC,$row->emailC,$row->passwordC,$row->prenomC,$row->favorisCl,$row->favorisPh);
        $i++;
    }

         echo  json_encode($responce);
    $this->load->view('admin/homev');

}
my view
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;Demonstration how programatically select grid row which are not on the first page&lt;/title&gt;
    &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;

   &lt;link rel="stylesheet" type="text/css" href="themes/redmond/jquery-ui-1.8.2.custom.css" /&gt;
    &lt;link rel="stylesheet" type="text/css" href="js/src/css/ui.jqgrid.css" /&gt;
        &lt;link rel="stylesheet" type="text/css" href="js/src/css/jquery.searchFilter.css" /&gt;
    [removed][removed]
    [removed][removed]
    [removed][removed]







    &lt;title&gt;Codeigniter With JQGrid&lt;/title&gt;


[removed]




        $(document).ready(function (){
            jQuery("#list").jqGrid({
                url:'&lt;?php=$base_url.'/home/loadData'?&gt;',
  // url:'http://localhost/pfe/home/loadData',      //another controller function for generating data
//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:['Name','Email','Passport','Phone','Fax','Address'],       //Grid column headings
                colModel:[
                    {name:'nomC',index:'nomC', width:100, align:"left"},
                    {name:'emailC',index:'emailC', width:150, align:"left"},
                    {name:'passwordC',index:'passwordC', width:100, align:"right"},
                    {name:'prenomC',index:'prenomC', width:100, align:"right"},
                    {name:'favorisCl',index:'favorisCl', width:100, align:"right"},
                    {name:'favorisPh',index:'favorisPh', width:100, align:"right"},
                ],
                rowNum:10,
                width: 750,
                height: 300,
                rowList:[10,20,30],
                pager: '#pager',
                sortname: 'id',
    

                viewrecords: true,
                rownumbers: true,
                gridview: true,
                caption:"List Of Person"
            }).navGrid('#pager',{edit:false,add:false,del:false});
        });
    


   [removed]  

&lt;body&gt;

    <center>
        <h1>Codeigniter With JQGrid</h1>
    &lt;?php
        $ci =& get_instance();
        $base_url = base_url();
    ?&gt;
    <table id="list">
    </table>&lt;!--Grid table--&gt;
    
    <div id="pager"></div>  &lt;!--pagination div--&gt;
    </center>


&lt;/body&gt;
&lt;/html&gt;
result is
Message: Undefined index: _search
and dat {"page":1,"total":2,"records":11,"rows":[{"id":"1","cell":["jouhri","jouhrimoham","mohamed","mohamed","1","2"]
#2

[eluser]InsiteFX[/eluser]
Your accessing _search in your post data but it is not defined anywhere's in your code!
#3

[eluser]djupond[/eluser]
I try to utliser jqgrid to present data in a table (grid)
I try to do it but it displays the data without grid
the model view controller and I have already published
here is the result


{"page":1,"total":2,"records":11,"rows":[{"id":"1","cell":["jouhri","jouhrimoham","mohamed","mohamed","1","2"]},{"id":"2","cell":["dridi","dridimarwen","marwen","marwen","2","3"]}
#4

[eluser]djupond[/eluser]
السلام عليكم ورحمة الله وبركاته

hello everyone, finally I found the solution to integrate into jqgrid codeignter
here is my solution:

this is my Model :
Code:
&lt;?php
    
class ClientModel extends CI_Model{
    
   private $table= 'client';

function __construct(){
  parent::__construct();
}

function count_all()
  
     {
  $this->db->select('*');
  $this->db->from('client');
  $query = $this->db->get();
  $data = $query->num_rows();
  return $data;
      }


  
  function get_data($sidx, $sord, $limit, $start){
  
  
  
  
  
   $data="";
                   $this->db->select('*');
                   $this->db->from('client');

     $this->db->order_by($sidx);
                   $this->db->limit($limit,$start);
  
                      $Q = $this-> db-> get();
         $data=$Q-> result();
         return $data ;


  }


                }

?&gt;

this is my Controller :
Code:
class Home extends CI_Controller {



    function __construct()
{
  parent::__construct();
    
            $this->load->model('clientModel');


  
}
    
      function index()
{
              $this->load->view('admin/homev');

}


function grid(){
        $page = isset($_POST['page'])?$_POST['page']:1;
        $limit = isset($_POST['rows'])?$_POST['rows']:10;
        $sidx = isset($_POST['sidx'])?$_POST['sidx']:'id';
        $sord = isset($_POST['sord'])?$_POST['sord']:'desc';        


        $start = $limit*$page - $limit;
$data->page =$page;
$count = $this->clientModel->count_all ();
        $data->records=$count;
        $data->total = ceil ($count /10 );
        $requette = $this-> clientModel-> get_data ($sidx, $sord, $limit, $start);
     $i=0;
    foreach($requette as $row) {
        $data->rows[$i]['id']=$row->id;
        $data->rows[$i]['cell']=array($row->nomC,$row->emailC,$row->passwordC,$row->prenomC,$row->favorisCl,$row->favorisPh);
        $i++;
    }



       echo json_encode ($data );

}
}

?&gt;


this my View :

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

&lt;html&gt;
&lt;head&gt;
    
    
    &lt;title&gt;Demonstration how programatically select grid row which are not on the first page&lt;/title&gt;
    &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
   &lt;link rel="stylesheet" type="text/css" href="http://localhost/pfe/design/js/jqgrid_demo38/themes/redmond/jquery-ui-1.8.2.custom.css" /&gt;

    &lt;link rel="stylesheet" type="text/css" href="http://localhost/pfe/design/js/jqgrid_demo38/js/src/css/ui.jqgrid.css" /&gt;
    [removed][removed]
    [removed][removed]
    [removed][removed]







&lt;/head&gt;
&lt;body&gt;

  







<table id="list12">
  
</table>


         <div id="pager12"></div>




        [removed]

    //&lt;![CDATA[

        jQuery(document).ready(function () {

jQuery("#list12").jqGrid({

    url:'http://localhost/pfe/home/grid',

datatype: "json",


    colNames:[' No','nomC', 'prenomC', 'emailC','Tax','Total','Notes'],

    colModel:[

     {name:'id',index:'id', width:55},

     {name:'nomC',index:'nomC', width:90},

     {name:'prenomC',index:'prenomC', width:100 },

     {name:'emailC',index:'emailC', width:80, align:"right"},

     {name:'passwordC',index:'passwordC', width:80, align:"right"},  

     {name:'favorisCl',index:'favorisCl', width:80,align:"right"},  

     {name:'favorisPh',index:'favorisPh', width:150, sortable:true}  

    ],

    rowNum:10,

    rowList:[10,20,30],

    pager: '#pager12',


    sortname: 'id',

    viewrecords: false,

    sortorder: "desc",

multiselect: false,

width: 500,

height: "100%",

caption: "dridi jouhri",
  gridview: true,
            loadonce: true,
         viewrecords: true,


});

jQuery("#list12").jqGrid("#list12","#pager12",{add:false,edit:false,del:false});

        });

    //]]>

    [removed]





&lt;/body&gt;
&lt;/html&gt;

Good Luck Wink




Theme © iAndrew 2016 - Forum software by © MyBB