2014-07-03 4 views
1

Si je veux filtrer mes colonnes, inclinez une lettre dans le champ de recherche et cliquez sur 'search' rien ne se passe. Mes enregistrements proviennent d'une base de données Mysql - tout fonctionne bien, peut tous les voir correctement dans ma table - juste le filtrage ne fonctionne pas pour moi.jqGrid - le filtre ne fonctionne pas

Quel est le problème que je ne peux voir aucune erreur.

Voici mes 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> 

et ici le fichier 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; 
?> 

Répondre

0

Je ne vois aucun code pour le traitement searchField et searchString partout dans votre code php. Si vous regardez la requête, la recherche doit être définie sur true et certains searchField searchString que vous devez gérer dans votre code afin de filtrer correctement les résultats sont inclus dans votre requête db. P.S .: Peut-être aussi.