我第一次使用jqgrid插件。一切都很好,除了网格从这里开始时没有加载的数据:http://imageshack.us/photo/my-images/16/capturadepantalla201305r.png“grid”。数据从数据库中获取,但只有在我点击任何标题/分类器时,它才会加载我的所有数据。我如何修复,从一开始就加载?我是一个完全的菜鸟,并希望任何帮助你们 这是我的代码:
我的PHP加载:
// Get the requested page. By default grid sets this to 1.
$page = $_GET['page'];
// get how many rows we want to have into the grid - rowNum parameter in the grid
$limit = $_GET['rows'];
// get index row - i.e. user click to sort. At first time sortname parameter -
// after that the index from colModel
$sidx = $_GET['sidx'];
// sorting order - at first time sortorder
$sord = $_GET['sord'];
// if we not pass at first time index use the first column for the index or what you want
if(!$sidx) $sidx =1;
// connect to the MySQL database server
$db = mysql_connect($dbhost, $dbuser, $dbpassword) or die("Connection Error: " . mysql_error());
// select the database
mysql_select_db($database) or die("Error connecting to db.");
// calculate the number of rows for the query. We need this for paging the result
$result = mysql_query("SELECT COUNT(*) AS count FROM demo");
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$count = $row['count'];
// calculate the total pages for the query
if( $count > 0 && $limit >5) {
$total_pages = ceil($count/$limit);
} else {
$total_pages = 5;
}
// if for some reasons the requested page is greater than the total
// set the requested page to total page
if ($page > $total_pages) $page=$total_pages;
// calculate the starting position of the rows
$start = $limit*$page - $limit;
// if for some reasons start position is negative set it to 0
// typical case is that the user type 0 for the requested page
if($start <0) $start = 0;
// the actual query for the grid data
$SQL = "SELECT id, name, id_continent, lastvisit,cdate, ddate,email FROM demo ORDER BY $sidx $sord LIMIT $start , $limit";
$result = mysql_query( $SQL ) or die("Couldn't execute query.".mysql_error());
// we should set the appropriate header information. Do not forget this.
header("Content-type: text/xml;charset=utf-8");
$s = "<?xml version='1.0' encoding='utf-8'?>";
$s .= "<rows>";
$s .= "<page>".$page."</page>";
$s .= "<total>".$total_pages."</total>";
$s .= "<records>".$count."</records>";
// be sure to put text data in CDATA
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
$s .= "<row id='". $row['id']."'>";
$s .= "<cell>". $row['id']."</cell>";
$s .= "<cell><![CDATA[". $row['name']."]]></cell>";
$s .= "<cell><![CDATA[". $row['id_continent']."]]></cell>";
$s .= "<cell>". $row['lastvisit']."</cell>";
$s .= "<cell>". $row['cdate']."</cell>";
$s .= "<cell>". $row['ddate']."</cell>";
$s .= "<cell><![CDATA[". $row['email']."]]></cell>";
$s .= "</row>";
}
$s .= "</rows>";
echo $s;
?>
HTML:
<link rel="stylesheet" type="text/css" media="screen" href="css/jquery-ui-1.10.3.custom.min.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/nhf.css" />
<style type="text/css">
html, body {
margin: 0;
padding: 0;
font-size: 90%;
}
</style>
<script src="js/jquery-1.9.0.min.js" type="text/javascript"></script>
<script src="js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
$("#list").jqGrid({
url:'request.php',
datatype: 'xml',
mtype: 'GET',
height: 'auto',
colNames:['id','Project', 'Assigned To','Assign Date','Check Date','Due Date','Attachments'],
colModel :[
{name:'id', index:'id', width:20},
{name:'name', index:'name', width:200, align:'left'},
{name:'id_continent', index:'id_continent', width:80, align:'right'},
{name:'lastvisit', index:'lastvisit', width:70, align:'right'},
{name:'cdate', index:'cdate', width:70, align:'right'},
{name:'ddate', index:'ddate', width:70, align:'right',datefmt:'(mm/d/YY)',date:'true'},
{name:'email', index:'email', width:70,align:'center',sortable:false}
],
pager: '#pager',
rowNum:10,
rowList:[10,20,30],
sortname: 'invid',
sortorder: 'desc',
viewrecords: true,
gridview: true,
caption: 'Pending Assignements'
});
});
</script>
</head>
答案 0 :(得分:0)
我明白了。我的排序名称错了。 sortname:'invid',它应该是“id”。感谢