2017-04-16 5 views
-1

私はあなたの助けが必要です 私はツールバーの検索でテーブルを持っています。 私はjqgrid 5.2、jquery 3.0、php 7を使っています。 私のコラムの1つに 'eq'、 'ne'、 'le'、 'lt'、 'gt'、 'ge'のような検索演算子があります。検索演算子を変更すると、サーバーに送信されたフィルターは変更できません。私は、検索演算子を変更する場合は別の値に「EQ」:それ `sの値は常に同じ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; 
} 
?> 
+0

検索演算子の機能を持っていませんか?問題は 'item'列にのみ存在しますか?列の 'searchoptions'に' sopt'を追加しようとしましたか?商用[Guriddo jqGrid JS](http://guriddo.net/?page_id=103334)の代わりに[free jqGrid](https://github.com/free-jqgrid/jqGrid)4.14.0を使用しようとしましたか? .0? – Oleg

答えて

0

loadCompleteは私のサーバーのコードです。しかし、それは動作していないようです。

fixSearchOperator関数はアイテム列の非表示検索演算子です。私は、単にqty列に検索演算子を表示したいだけです。

はい、私はqtyカラムでsoptを変更しようとしました。私がsoptの内容を変更したものであれば、最初の検索演算子オプションのみを送信します。

私はjqgrid 4.4.3を試してみましたが、それは `loadComplete`と` fixSearchOperators`のコードを持っているどのような目標はまだ

+0

私は自分の問題を解決しました。以前はjqgrid 5.0を使用していたからです。申し訳ありませんが、それは私のせいでした。それは働いて、私はjqgrid 5.2を使用します。お返事ありがとうございますOleg – candra

関連する問題