1
如果我想過濾我的列,請在搜索字段中輸入一些字母,然後單擊'搜索'沒有任何反應。 我的記錄來自Mysql數據庫 - 一切正常,可以在我的表格中正確地看到它們 - 只是過濾對我無效。jqGrid - 過濾器不工作
什麼問題我看不出任何錯誤。
這裏我的代碼:
(的index.html)
<title>My First Grid</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.0/themes/ui-darkness/jquery-ui.css">
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />
<style type="text/css">
html, body {
margin: 0;
padding: 0;
font-size: 75%;
}
</style>
<script src="//code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="js/i18n/grid.locale-de.js" type="text/javascript"></script>
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
$("#list").jqGrid({
url: "example.php",
datatype: "xml",
mtype: "GET",
width:600,
height: 'auto',
colNames: ["ID", "kundenName", "kundenVorName", "kundenPLZ", "kundenOrt"],
colModel: [
{ name: "id", width: 55 },
{ name: "kundenName", width: 90 },
{ name: "kundenVorName", width: 80, align: "right" },
{ name: "kundenPLZ", width: 80, align: "right" },
{ name: "kundenOrt", width: 80, align: "right" }
],
pager: "#pager",
rowNum: 10,
rowList: [10, 20, 30],
sortname: "id",
sortorder: "desc",
viewrecords: true,
gridview: true,
autoencode: true,
caption: "My first grid"
}).jqGrid('navGrid', '#pager', {
add: false,
edit: false,
del: false,
search: true,
refresh: true
});
});
</script>
</head>
<body>
<table id="list"><tr><td></td></tr></table>
<div id="pager"></div>
</body>
</html>
這裏的PHP文件:
<?php
$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
$con = mysqli_connect("", "root", "") or die("Connection Error: ");
// select the database
mysqli_select_db($con,"kunden") or die("Error connecting to db.");
// calculate the number of rows for the query. We need this for paging the result
$result = mysqli_query($con,"SELECT COUNT(*) AS count FROM personen");
$row = mysqli_fetch_array($result,MYSQL_ASSOC);
$count = $row['count'];
// calculate the total pages for the query
if($count > 0 && $limit > 0) {
$total_pages = ceil($count/$limit);
} else {
$total_pages = 0;
}
// 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,kundenName,kundenVorName,kundenPLZ,kundenOrt FROM personen ORDER BY $sidx $sord LIMIT $start , $limit";
$result = mysqli_query($con,$SQL) or die("Couldn't execute query.".mysqli_error($con));
// 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 = mysqli_fetch_array($result,MYSQL_ASSOC)) {
$s .= "<row id='". $row['id']."'>";
$s .= "<cell>". $row['id']."</cell>";
$s .= "<cell>". $row['kundenName']."</cell>";
$s .= "<cell>". $row['kundenVorName']."</cell>";
$s .= "<cell>". $row['kundenPLZ']."</cell>";
$s .= "<cell>". $row['kundenOrt']."</cell>";
$s .= "</row>";
}
$s .= "</rows>";
echo $s;
?>