당신의 도움이 필요합니다. 툴바 검색 기능이있는 테이블이 있습니다. jqgrid 5.2, jquery 3.0 및 php 7을 사용합니다. 내 열 중 하나에 'eq', 'ne', 'le', 'lt', 'gt', 'ge'과 같은 검색 연산자가 있습니다. 검색 연산자를 변경하면 서버로 보낸 필터를 변경할 수 없습니다. 내가 검색 연산자를 변경하면 다른 값으로 "EQ" :`의 값은 항상 같은Jqgrid가 검색 연산자를 서버에 동적으로 전송했습니다.
{"groupOp":"AND","rules":[{"field":"item",**"op":"eq"**,"data":"12"}]}
내 질문은 "OP"로 변경하는 방법은?
이 내있는 jqGrid 코드
function fixSearchOperators() {
var $grid = $("#list"),
columns = $grid.jqGrid ('getGridParam', 'colModel'),
filterToolbar = $($grid[0].grid.hDiv).find("tr.ui-search-toolbar");
filterToolbar.find("th").each(function(index) {
var $searchOper = $(this).find(".ui-search-oper");
if (!(columns[index].searchoptions &&
columns[index].searchoptions.searchOperators)) {
$searchOper.hide();
}
});
}
var mygrid =
$("#list").jqGrid({
url:'tabel/tablejson.php?q=1',
datatype: 'json',
mtype: "POST",
colNames:['Item','Qty'],
colModel :[
{name:'item', index:'item', width:240,
editable:true, editoptions:{size:20, maxlength:'20'},
editrules:{required:true}, sorttype:'string',
searchoptions:{clearSearch: false},
formoptions:{elmprefix:"(*)"}},
{name:'qty', index:'qty', width:50, align:'right', editable:true,
editoptions:{size: 5}, editrules:{required:true, number:true},
sorttype:'integer',searchoptions:{sopt:['eq', 'ne', 'le', 'lt', 'gt', 'ge'],
searchOperators: true, clearSearch: false},
formoptions:{elmprefix:"(*)",elmsuffix:""}}
],
multiselect: true,
altRows: true,
altclass: 'myAltRowClass',
pager: '#pager',
rowNum:500,
rownumbers: true,
rownumWidth: 20,
gridview: true,
pginput: false,
height: 380,
shrinkToFit: false,
width: 390,
sortname: 'Qty',
sortorder: 'asc',
scrollOffset:0,
viewrecords: true,
caption: 'TEST',
editurl:"edit/editjson.php",
loadComplete: function() {
//reset search operator
$("a.soptclass[colname='FieldName']").attr("soper","eq");
$("a.soptclass[colname='FieldName']").text("==");
}
});
$("#list").jqGrid('navButtonAdd',"#pager", {
caption:"Reset",
title:"Reset Filter",
buttonicon:'ui-icon-refresh',
onClickButton:function(){
mygrid[0].clearToolbar()
}
});
$("#list").jqGrid('filterToolbar', {
multipleSearch: true,
searchOnEnter: false,
searchOperators: true,
stringResult: true,
defaultSearch: "cn"
});
fixSearchOperators();
입니다 이것은 내가 도구 모음에서 필터를 재설정 할 때 자동으로 검색 연산자를 재설정하기위한
<?php
include '../config/connections.php';
$examp = $_REQUEST["q"]; //query number
$page = $_REQUEST['page']; // get the requested page
$limit = $_REQUEST['rows']; // get how many rows we want to have into the grid – rowNum parameter in the grid
$sidx = $_REQUEST['sidx']; // get index row - i.e. user click to sort. At first time sortname parameter - after that the index from colModel
$sord = $_REQUEST['sord']; // get the direction
if(!$sidx) $sidx =1;// if we not pass at first time index use the first column for the index or what you want
$filters = str_replace('\"','"' ,$_POST['filters']);
$search = $_POST['_search'];
$where = "";
if(($search==true) &&($filters != "")) {
$filters = json_decode($filters);
$where = " WHERE ";
$whereArray = array();
$rules = $filters->rules;
$groupOperation = $filters->groupOp;
foreach($rules as $rule) {
$fieldName = $rule->field;
$fieldData = mysqli_real_escape_string($db,$rule->data);
switch ($rule->op) {
case "eq":
$fieldOperation = " = '".$fieldData."'";
break;
case "ne":
$fieldOperation = " != '".$fieldData."'";
break;
case "lt":
$fieldOperation = " < '".$fieldData."'";
break;
case "gt":
$fieldOperation = " > '".$fieldData."'";
break;
case "le":
$fieldOperation = " <= '".$fieldData."'";
break;
case "ge":
$fieldOperation = " >= '".$fieldData."'";
break;
case "nu":
$fieldOperation = " = ''";
break;
case "nn":
$fieldOperation = " != ''";
break;
case "in":
$fieldOperation = " IN (".$fieldData.")";
break;
case "ni":
$fieldOperation = " NOT IN '".$fieldData."'";
break;
case "bw":
$fieldOperation = " LIKE '".$fieldData."%'";
break;
case "bn":
$fieldOperation = " NOT LIKE '".$fieldData."%'";
break;
case "ew":
$fieldOperation = " LIKE '%".$fieldData."'";
break;
case "en":
$fieldOperation = " NOT LIKE '%".$fieldData."'";
break;
case "cn":
$fieldOperation = " LIKE '%".$fieldData."%'";
break;
case "nc":
$fieldOperation = " NOT LIKE '%".$fieldData."%'";
break;
default:
$fieldOperation = "";
break;
}
if($fieldOperation != "") $whereArray[] = $fieldName.$fieldOperation;
}
if (count($whereArray)>0) {
$where .= join(" ".$groupOperation." ", $whereArray);
} else {
$where = "";
}
}
switch ($examp) {
case 1:
// calculate the number of rows for the query. We need this for paging the result
$query = "SELECT COUNT(*) AS count FROM test".$where;
$result = $db->query($query);
$row = $result->fetch_array(MYSQLI_ASSOC);/* associative array */
$count = $row['count'];
// calculate the total pages for the query
if($count >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; // do not put $limit*($page - 1)
// 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 * FROM test".$where." ORDER BY ".$sidx." ".$sord. " LIMIT ".$start." , ".$limit;
$result = $db->query($SQL) or die("Couldn't execute query.".mysqli_error($db));
// Construct the json data
$responce->page = $page;// current page
$responce->total = $total_pages;// total pages
$responce->records = $count;// total records
$i=0;
while($row = $result->fetch_array(MYSQLI_ASSOC)) {
$responce->rows[$i]['id']=$row['item'];
$responce->rows[$i]['cell']=array($row['item'],$row['qty']);
$i++;
}
//echo $json->encode($responce); // coment if php 5
echo json_encode($responce);
break;
case 3:
}
mysqli_close($db);
function Strip($value)//a function called Strip that will remove slashes from the user typed text
{
if(get_magic_quotes_gpc() != 0)
{
if(is_array($value))
if (array_is_associative($value))
{
foreach($value as $k=>$v)//more or less this is pretty much saying for every value that the user entered in *note that the $v is data that comes out of your Strip function which as I mentioned it removes slashes from the user typed fields.
$tmp_val[$k] = stripslashes($v);
$value = $tmp_val;
}
else
for($j = 0; $j < sizeof($value); $j++)
$value[$j] = stripslashes($value[$j]);
else
$value = stripslashes($value);
}
return $value;
}
function array_is_associative ($array)
{
if (is_array($array) && ! empty($array))
{
for ($iterator = count($array) - 1; $iterator; $iterator--)
{
if (! array_key_exists($iterator, $array)) { return true; }
}
return ! array_key_exists(0, $array);
}
return false;
}
?>
를 검색 연산자 기능을하지? 문제가'item' 칼럼에만 존재합니까? 열에'searchoptions'에'sopt'를 추가하려고 했습니까? 상용 [Guriddo jqGrid JS] (http://guriddo.net/?page_id=103334) 5.2 대신 [free jqGrid] (https://github.com/free-jqgrid/jqGrid) 4.14.0을 사용하려고합니까? .0? – Oleg