2011-11-09 1 views
0

CodeIgniterとjqGridを使用すると問題が発生します。グリッドは正しいデザインですが、データをグリッドにロードしません。表示されるメッセージは「未定義」です。CodeIgniter jqGrid undefined

<head> 
    <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/themes/dark-hive/jquery-ui.css" type="text/css" rel="stylesheet"/> 
    <link href="http://static.jquery.com/ui/css/demo-docs-theme/ui.theme.css" type="text/css" rel="stylesheet"/> 
    <link type="text/css" href="<?php echo base_url()?>asset/jqgrid/css/ui.jqgrid.css" rel="stylesheet" /> 
    <link type="text/css" href="<?php echo base_url()?>asset/jqgrid/css/jquery.searchFilter.css" rel="stylesheet" /> 
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js" type="text/javascript"></script> 
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js" type="text/javascript"></script> 
    <script src="<?php echo base_url(); ?>'asset/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script> 
    <script src="<?php echo base_url(); ?>asset/jqgrid/js/jquery.jqGrid.js" type="text/javascript"></script> 
    <script src="<?php echo base_url(); ?>asset/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script> 
    <title>Jqgrid</title> 
</head> 
<body> 
    <script type="text/javascript"> 
     jQuery().ready(function(){ 
      jQuery("#list").jqGrid({ 
       url:'<?php echo base_url().'index.php/jqgrid/example'?>', 
       mtype : "post", 
       datatype: "json", 
       colNames:['Inv No','Date', 'Amount','Tax','Total','Notes'], 
       colModel :[ 
        {name:'invid', index:'invid', width:20}, 
        {name:'invdate', index:'invdate', width:90, align:'center',editable:true, formatter:'date',editrules: { required: true, date:true}, formatoptions:{srcformat:'Y-m-d', newformat:'m/d/Y'}}, 
        {name:'amount', index:'amount', width:80, align:'center',editable:true,edittype:'text'}, 
        {name:'tax', index:'tax', width:80, align:'center',editable:true,edittype:'text'}, 
        {name:'total', index:'total', width:80, align:'center',editable:true, edittype:'text'}, 
        {name:'note', index:'note', width:150, align:'center', sortable:false,editable:true,edittype:'text'} 
       ], 
       rowNum:10, 
       width: 800, 
       height: 200, 
       rowList:[10,20,30,40,50,60,70], 
       pager: '#gridpager', 
       sortname: 'invid', 
       viewrecords: true, 
       caption:"CLientes" 
      }).navGrid(
       '#gridpager', 
       {view:true,edit:true,add:true,del:true,search:true}, 
       {closeAfterEdit:true,modal:true}, // use default settings for edit 
       {}, // use default settings for add 
       {}, // delete instead that del:false we need this 
       {}, // enable the advanced searching 
       {closeOnEscape:true} /* allow the view dialog to be closed when user press ESC key*/ 
      ); 
     }); 
    </script> 
    <table id="list"></table> 
    <div id="gridpager"></div> 
</body> 

class jqgrid extends CI_Controller { 

    function __construct() 
    { 
     parent::__construct(); 
     $this->load->helper(array('url')); 
     $this->load->model('cliente'); 
     $this->load->database(); 
    } 

    function index() 
    { 
      $this->load->view('jqgrid/home'); 
    } 

    function example() 
    { 
     $hal = isset($_POST['page'])?$_POST['page']:1; 
     $batas = isset($_POST['rows'])?$_POST['rows']:10; 
     $sidx = isset($_POST['sidx'])?$_POST['sidx']:'invid'; 

     if(!$sidx) $sidx=1; 

     $q = $this->cliente->cargar(); 
     $hitung = count($q); 

     if($hitung > 0) { 
      $total_hal = ceil($hitung/$batas); 
     } else { 
      $total_hal = 0; 
     } 

     if ($hal > $total_hal) $hal=$total_hal; 

     $start = $batas*$hal - $batas; 
     $start = ($start < 0) ? 0 : $start; 

     $data->page = $hal; 
     $data->total = $total_hal; 
     $data->records = $hitung; 

     $i=0; 
     foreach($q->result() as $row) { 
      $data->rows[$i]['id']=$row->invid; 
      $data->rows[$i]['cell']=array($i+1,$row->invdate,$row->amount,$row->tax,$row->total,$row->note); 
      $i++; 
     } 
     echo json_encode($data); 
    } 

} 

答えて

0

class cliente extends CI_Model{ 

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

    function cargar() 
    { 
     $q = $this->db->query("select * from invheader"); 
     return $q; 
    } 

} 

私は次のような問題は、/あなたのコード内の疑いのある場所を参照してください:すべてのファイル jquery.searchFilter.css

  • まずが、多くの再送信に使用されていないことになりますjqGridバージョン。
  • jquery.jqGrid.jsjquery.jqGrid.min.jsの両方を含むことは間違いです。
  • 私はPHPを自分で使用しませんが、"<?php echo base_url(); ?>'asset/jqgrid/js/i18n/grid.locale-en.js"は間違っています。おそらく"<?php echo base_url(); ?>asset/jqgrid/js/i18n/grid.locale-en.js"を意味するでしょう(真ん中に'の文字はありません)。
  • 私はPHPの構文は分かりませんが、url:'<?php echo base_url().'index.php/jqgrid/example'?>'も同様の意味があると思われますurl:'<?php echo base_url("index.php/jqgrid/example");?>'
+0

回答ありがとうございますが問題は解決策ではありません – user1037726

+0

@ user1037726:申し訳ありませんが、「問題の検索ソリューションではない」という意味を理解できていませんか? – Oleg

+0

http://pastebin.com/Hg5WNic0 – user1037726