最上面的数据是
121310000-00-00-00103.9845.34149.32这是记录120000-00-00-00-00104.9846.34159.32 This This Record 230000-00-00-00104.9846.34159.32这是记录240000-0000-0000-00-00-00104.9846.346.346.34159.34159.34159.34159.34159.34159.34159.34159.34159.3232thisisis IS- 260000-00-00104.9846.34159.32This is record 272011-09-07108.9850.34159.32This is record 682011-09-07108.9850.34159.32This is record 792011-09-07108.9850.34159.32This is record 8102011-09-07108.9850.34159.32This is record 9
然后网格有列名但没有数据。我不知道怎么了。如何获取网格内的数据?
控制器:
function loadDataGrid() {
$this->load->view('test2');//test.php view file
$page = isset($_POST['page']) ? $_POST['page'] : 1; // get the requested page
$limit = isset($_POST['rows']) ? $_POST['rows'] : 10; // get how many rows we want to have into the grid
$sidx = isset($_POST['sidx']) ? $_POST['sidx'] : 'name'; // get index row - i.e. user click to sort
$sord = isset($_POST['sord']) ? $_POST['sord'] : ''; // get the direction
$start = $limit * $page - $limit; // do not put $limit*($page - 1)
$start = ($start < 0) ? 0 : $start; // make sure that $start is not a negative value
$where = ""; //if there is no search request sent by jqgrid, $where should be empty
$searchField = isset($_POST['searchField']) ? $_POST['searchField'] : false;
$searchOper = isset($_POST['searchOper']) ? $_POST['searchOper'] : false;
$searchString = isset($_POST['searchString']) ? $_POST['searchString'] : false;
$this->load->model('users');
if (!$sidx)
$sidx = 1;
$count = $this->users->total_results(); //get total rows from table daily
if ($count > 0) {
$total_pages = ceil($count / $limit); //calculating total number of pages
} else {
$total_pages = 0;
}
if ($page > $total_pages)
$page = $total_pages;
$query = $this->users->getAllGrid($start, $limit, $sidx, $sord, $where); //add parameter to model
$responce->page = $page;
$responce->total = $total_pages;
$responce->records = $count;
$this->output->set_header("Content-type: text/xml;charset=utf-8");
$s = "<?xml version='1.0' encoding='utf-8'?>";
$s .= "<rows>";
$s .= "<page>" . $responce->page . "</page>";
$s .= "<total>" . $responce->total . "</total>";
$s .= "<records>" . $responce->records . "</records>";
foreach ($query as $row) {
$s .= "<row id='" . $row['invid'] . "'>";
$s .= "<cell>" . $row['invid'] . "</cell>";
$s .= "<cell>" . $row['invdate'] . "</cell>";
$s .= "<cell>" . $row['amount'] . "</cell>";
$s .= "<cell>" . $row['tax'] . "</cell>";
$s .= "<cell>" . $row['total'] . "</cell>";
$s .= "<cell>" . $row['note'] . "</cell>";
$s .= "</row>";
}
$s .= "</rows>";
echo $s;
}
看法:
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/themes/base/jquery-ui.css" type="text/css" media="all" />
<link rel="stylesheet" href="http://static.jquery.com/ui/css/demo-docs-theme/ui.theme.css" type="text/css" media="all" />
<link type="text/css" href="<?php echo base_url() ?>jqgrid/css/ui.jqgrid.css" rel="stylesheet" />
<link type="text/css" href="<?php echo base_url() ?>jqgrid/css/jquery.searchFilter.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/jquery-ui.min.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>jqgrid/js/i18n/grid.locale-en.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>jqgrid/jquery.jqGrid.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>jqgrid/jquery.jqGrid.min.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>jqgrid/jquery.layout.js"></script>
<title>Demo Jquery JqGrid Codeigniter</title>
</head>
<body>
<?
$ci = & get_instance();
$base_url = base_url();
?>
<script type="text/javascript">
jQuery().ready(function (){
jQuery("#list1").jqGrid({
url:'<?= $base_url . 'index.php/daily/loadDataGrid' ?>', //another controller function for generating data
mtype : "post", //Ajax request type. It also could be GET
datatype: "json", //supported formats XML, JSON or Arrray
colNames:['Date','Name','Amount'], //Grid column headings
colModel:[
{name:'invid', index:'invid', width:55},
{name:'invdate', index:'invdate', width:90},
{name:'amount', index:'amount', width:80, align:'right'},
{name:'tax', index:'tax', width:80, align:'right'},
{name:'total', index:'total', width:80, align:'right'},
{name:'note', index:'note', width:150, sortable:false}
],
rowNum:10,
width: 450,
height: 300,
rowList:[10,20,30],
pager: '#pager1',
sortname: 'id',
viewrecords: true,
rownumbers: true,
gridview: true,
caption:"List Daily"
}).navGrid('#pager1',{edit:false,add:false,del:false});
});
</script>
<table id="list1"></table> <!--Grid table-->
<div id="pager1"></div> <!--pagination div-->
</body>
</html>
模型:
function getAllGrid($start, $limit, $sidx, $sord, $where) {
$this->db->select('invid,invdate,client_id,amount,tax,total,note');//->from('invheader');
$this->db->limit($limit);
if ($where != NULL
)$this->db->where($where, NULL, FALSE);
$this->db->order_by('invid',$sord);//$sord $sidx
$query = $this->db->get('invheader', $limit, $start);
return $query->result_array();
}