看官網的php 也不像會有search的結果...
最後還是上網找
server.php (同官網範例,就在下sql那段 加入這個)
$where = "WHERE 1=1 " . constructWhere();
$SQL = "SELECT ... FROM xxx $where ORDER BY $sidx $sord LIMIT $start , $limit";
...
//--------------------------
function constructWhere(){
$wh = "";
$searchOn = $_REQUEST['_search'];
if($searchOn=='true')
{
$fld = $_REQUEST['searchField'];
//過濾欄位,填入會用到search的欄位
if(!( $fld=='id' || $fld =='name'))
{
$fldata = $_REQUEST['searchString'];
$foper = $_REQUEST['searchOper'];
//construct where
$wh .= " AND " . $fld;
switch ($foper) {
case "bw":
$fldata .= "%";
$wh .= " LIKE '" . $fldata."'";
break;
case "eq":
if(is_numeric($fldata)) {
$wh .= " = " . $fldata;
}else{
$wh .= " = '" . $fldata."'";
}
break;
case "ne":
if(is_numeric($fldata)) {
$wh .= " <> " . $fldata;
}else{
$wh .= " <> '" . $fldata . "'";
}
break;
case "lt":
if(is_numeric($fldata)) {
$wh .= " < " . $fldata;
} else {
$wh .= " < '" . $fldata."'";
}
break;
case "le":
if(is_numeric($fldata)) {
$wh .= " <= " . $fldata;
}else {
$wh .= " <= '" . $fldata."'";
}
break;
case "gt":
if(is_numeric($fldata)) {
$wh .= " > ".$fldata;
} else {
$wh .= " > '".$fldata."'";
}
break;
case "ge":
if(is_numeric($fldata)) {
$wh .= " >= ".$fldata;
} else {
$wh .= " >= '".$fldata."'";
}
break;
case "ew":
$wh .= " LIKE '%".$fldata."'";
break;
case "ew":
$wh .= " LIKE '%".$fldata."%'";
break;
default :
$wh = "";
}
}
return $wh;
}
Reference
忘了哪看的了...
接收完成的callback function
jQuery("#tbSearch").jqGrid({
datatype:function(postdata) {
jQuery.ajax({
url: "server.php", //原本寫在外面的,現在外面那個就參考用
data:postdata,
datatype:"json",
complete:function(xmldata,stat){
if(stat=="success") {
//xmldata是XMLHttpRequest, 所以如果是datatype的話,就要 xmldata.responseXML
alert(xmldata.responseText);
}
}
});
},
...
Reference
Data Manipulation
jqGrid 的多字段查詢