Codeigniter jqGrid
I have a problem to show data in jqGrid when I'm using codeigniter framework. I've made a test with nearly the same code without codeigniter and everthing is o.k. I can see data in the grid.
I'm using codeigniter 2.01, jquery 1.6.2 und jqGrid 4.1.2 Here is my code, every help is appreciated.
Controller 1: (I'm using a template and the function schulform calls die view 'grid.php')
public function schulform()
{
fill_template('grid',navigation(),'banner_login');
}
Controller 2: (I know the sql-statements should be in a model, this is just for testing)
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 .= "<c开发者_如何转开发ell>'". $row['SFId']."'</cell>";
$s .= "<cell><![CDATA[". $row['Schulformname']."]]></cell>";
$s .= "</row>";
}
$s .= "</rows>";
echo $s;
}
}
View (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>
Function fill_template is in a helper:
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();
}
And finally this is the data which is generated by gridserver/start when I call these function directly (I deletet all < and > brackets for showing the code here):
- 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
I found my error. I had to put the javascript-code with the help of the template into the header. Now the data in jqgrid is displayed.
精彩评论