CodeIgniter jqGrid未定义

时间:2011-11-09 13:24:42

标签: codeigniter jqgrid

使用CodeIgniter和jqGrid时遇到问题。网格具有正确的设计,但不会将数据加载到网格中。显示的消息是“未定义”。

<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 cliente extends CI_Model{

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

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

}

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);
    }

}

1 个答案:

答案 0 :(得分:0)

我在您的代码中看到以下问题/可疑位置:

  • 首先,文件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"(中间没有' charachter)。
  • 我不知道PHP语法,但url:'<?php echo base_url().'index.php/jqgrid/example'?>'似乎也被怀疑是url:'<?php echo base_url("index.php/jqgrid/example");?>'的意思?
相关问题