Marko Aleksić
Marko Aleksić

Reputation: 1591

jqGrid and CodeIgniter Problem

I have problem with loading my jqGrid. It just loads two parallel lines, and shows "Loading..." above them. This is my controller:

function grid()
{
    $var['grid'] = $this->Uom_model->select();
         $i = 0;
         foreach($var['grid'] as $row) 
         {
            $response->rows[$i]['id']=$row->id;
            $response->rows[$i]['cell']=array($row->id,$row->uname);
            $i++;
         }
   echo json_encode($response);


}

This is my View:

$(document).ready(function() { 

    jQuery("#list27").jqGrid({
           url:'<?php echo base_url();?>index.php/uom/grid',
           datatype: "json",
           mtype: "post",
           height: 250,
           width: 450,
           colNames:['ID','Unit of Measure'],
           colModel:[
                  {name:'id',index:'id', width:65},
                  {name:'uname',index:'uname'}
              ],
           rowNum:50,
           rowTotal: 2000,
           rowList : [20,30,50],
           loadonce:true,
           rownumbers: true,
           rownumWidth: 40,
           gridview: true,
           pager: '#pager27',
           viewrecords: true,
           sortorder: "asc",
           caption: "Loading data from server at once"    
       });
}); 

The JSON output if I run only the function "grid" from the controller is:

{"rows":[{"id":"1","cell":["1","grams"]},{"id":"2","cell":["2","hour"]},{"id":"3","cell":["3","kilo"]},{"id":"4","cell":["4","liter"]},{"id":"5","cell":["5","pcs"]}]}

Thank you in advance.

Upvotes: 0

Views: 1185

Answers (1)

Oleg
Oleg

Reputation: 221997

I could not reproduce your problem, but the grid from my test (see here) have wrong row numbers. Using jsonReader

jsonReader: {
    page: function (obj) { return 1; },
    total: function (obj) { return 1; },
    records: function (obj) { return obj.rows.length; }
}

one can solve the problem: see here.

Upvotes: 1

Related Questions