2012-03-06 63 views
0

我正在嘗試使用PHP MVC結構的JqGrid。 我不想使用Jq Grid的搜索功能,而是我想要一般關鍵字搜索。 我在json數組中有數據。請讓我知道如何使用我的json數據集執行搜索。在JqGrid中的Custome搜索表單

該搜索應該在多列上執行。

這是我的搜索形式

<form name="frmsearch" id="frmsearch"> 
    <input type="text" id="txtsearch" name="txtsearch"/> 
    <a href="javascript:void(0);" onClick="doSearch();">Search</a> 
</form> 

,這是我的網

$(document).ready(function() { 
    jQuery("#agentlist").jqGrid({ 
     url: "manageagents/getagents/", 
     datatype: "json",     
     mtype:"POST", 
     jsonReader: { 
      root: "rows", 
      page: "currpage", 
      total: "totalpages", 
      records: "totalrecords", 
      id: "0", 
      cell:"", 
      repeatitems: false 
     }, 
     colNames: ['Id','Agent Name', 'Email Address', 'Phone No.1', 'Phone No.2','City', 'State', 'Country'], 
     colModel: [ 
       ... ... ... 
        ], 
     rowNum:<?php echo $this->config->item('per_page');?>, 
     rowList:<?php echo $this->config->item('nav_page');?>, 
     pager: '#plist', 
     autowidth: true, 
     height: "100%", 
     loadonce: true, 
     viewrecords: true, 
     altRows:true,     
     caption: "", 
    }).navGrid('#plist', { edit: false, add: false, del: false, search: true, refresh: false }); ; 
}); 

請讓我知道,如果需要更多的信息。

回答

1

最簡單的做法是將當前值從搜索輸入字段#txtsearch發送到URL "manageagents/getagents/"。這足以補充postData參數與像將被髮送到服務器的參數(如myFilter)的名稱的屬性:

postData: { 
    myFilter: function() { return $("#txtsearch").val(); } 
} 

您可以在the answer閱讀更多細節。

doSearch功能,你可以叫

jQuery("#agentlist").trigger("reloadGrid", [{page: 1}]); 
+0

它的作品。謝謝 !!! – pinaldesai 2012-03-06 10:14:35

+0

@pinaldesai:不客氣! – Oleg 2012-03-06 10:17:36