当我使用codeigniter框架时,我在jqGrid中显示数据时遇到问题。 我用几乎相同的代码进行了测试,没有codeigniter,而且everthing是o.k.我可以在网格中看到数据。
我正在使用codeigniter 2.01,jquery 1.6.2和jqGrid 4.1.2 这是我的代码,感谢每一个帮助。
控制器1 :(我正在使用模板,函数schulform调用die视图'grid.php')
public function schulform()
{
fill_template('grid',navigation(),'banner_login');
}
控制器2 :(我知道sql语句应该在模型中,这只是用于测试)
class Gridserver extends CI_Controller {
public function __construct()
{
parent::__construct();
[.... css and js-Files....]
}
public function start()
{
$page = $this->input->post('page',true);
$limit = $this->input->post('rows',true);
$sidx = $this->input->post('sidx',true);
$sord = $this->input->post('sord',true);
if(!$sidx) $sidx =1;
$sql="SELECT * FROM tbl_schulform";
$query = $this->db->query($sql);
$count = $query->num_rows();
if( $count > 0 && $limit > 0) {
$total_pages = ceil($count/$limit);
} else {
$total_pages = 0;
}
if ($page > $total_pages) $page=$total_pages;
$start = $limit*$page - $limit;
if($start <0) $start = 0;
$sql = "SELECT SFId,Schulformname from tbl_schulform";
$query = $this->db->query($sql);
//just for testing
$page="1";
$total_pages="1";
$count="3";
$et='>';
$this->output->set_content_type("content-type: text/xml");
$s = "<?xml version='1.0' encoding='utf-8'?$et\n";
$s = "<rows>";
$s .= "<page>".$page."</page>";
$s .= "<total>".$total_pages."</total>";
$s .= "<records>".$count."</records>";
foreach($query->result_array() as $row){
$s .= "<row id='". $row['SFId']."'>";
$s .= "<cell>'". $row['SFId']."'</cell>";
$s .= "<cell><![CDATA[". $row['Schulformname']."]]></cell>";
$s .= "</row>";
}
$s .= "</rows>";
echo $s;
}
}
查看(grid.php):
<script type="text/javascript">
$(function(){
jQuery('#listSchulform').jqGrid({
url:'<?=base_url().'gridserver/start'?>',
datatype: 'xml',
mtype: 'post',
colNames:['ID', 'Schulformname'],
colModel :[
{name:'SFId', index:'SFId', width:400},
{name:'Schulformname', index:'Schulformname', width:150}
],
pager: '#pager',
rowNum:15,
rowList:[15,30,45],
sortname: 'Schulformname',
sortorder: 'asc',
viewrecords: true,
caption: 'Schulform',
editurl:"",
height:335
});
});
</script>
<center><table id='listSchulform'></table></center>
<div id='pager'></div>
函数fill_template在帮手中:
function fill_template($content,$navi,$login)
{
$ci=& get_instance();
$ci->template->write('title','DWO');
$ci->template->write_view('content',$content);
if ($navi != '')
$ci->template->write('navi',$navi);
if ($login != '')
$ci->template->write_view('login',$login);
$footer="Footer dummy";
$ci->template->write('footer',$footer);
$ci->template->render();
}
最后这是我直接调用这些函数时gridserver / start生成的数据(我删除所有&lt;和&gt;括号以显示代码):
- rows page1/page total1/total records3/records - row id="1" cell'1'/cell - cell - ![CDATA[ Berufsschule ]] /cell /row - row id="2" cell'2'/cell - cell - ![CDATA[ Vollzeitschulform ]] /cell /row - row id="3" cell'3'/cell - cell - ![CDATA[ test ]] /cell /row /rows
答案 0 :(得分:0)
我发现了我的错误。我必须在模板的帮助下将javascript代码放入标题中。现在显示jqgrid中的数据。