jqGrid - 过滤器无法正常工作

时间:2014-07-03 11:18:45

标签: php jquery jqgrid

如果我想过滤我的列,请在搜索字段中输入一些字母,然后点击“搜索”,不会发生任何事情。 我的记录来自一个Mysql数据库 - 一切正常,可以在我的表中正确看到所有这些 - 只是过滤对我不起作用。

问题是什么,我看不出任何错误。

这是我的代码:

(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;
?>

1 个答案:

答案 0 :(得分:0)

我在PHP代码中的任何地方都没有看到任何处理searchFieldsearchString的代码。如果您查看请求,它应该将搜索设置为true,并且您需要在代码中处理一些searchField搜索字符串,以便正确过滤结果a.k.a.将其包含在您的数据库查询中。 P.S。:也许searchOper