duanquannan0593 2014-07-03 11:18
浏览 81

jqGrid - 过滤器无法正常工作

If i want to filter my columns, tip some letter into the search field and click 'search' nothing happens. My records are coming from a Mysql Database - all works fine, can see all of them correctly in my table - just the filtering doesn´t work for me.

What´s the problem i can´t see any mistake.

Here my codes:

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

and here the PHP file:

<?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条回答 默认 最新

  • doulou1989 2014-07-03 18:51
    关注

    I'm not seeing any code for handling searchField and searchString anywhere in your php code. If you look at the request it should have search set to true and some searchField searchString which you need to handle in your code in order to properly filter the results a.k.a. include it in your db query. P.S.: Maybe searchOper too.

    评论

报告相同问题?

悬赏问题

  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算