2011-11-17 56 views
0

自從幾個月前我一直在參觀這個論壇,沒有註冊,我真的很喜歡它。所以,提前感謝所有成員。現在我想提出我的第一個問題。如何從服務器端的jqgrid獲取搜索參數?

我一直在使用Jqgrid,我已經設法讓它顯示行和按鈕,但現在我需要做一個搜索,一個複雜的,我認爲「自動」jqgrid將發送參數到服務器,我的意思是:

元數,searchField,索珀,searchOper,S值,搜索字符串,sFilter和/或過濾器

我不知道在所有哪些它必須發送,並且我認爲它會發送'page','rows'和'sord'。但我失去了一些東西,因爲,例如,我能得到「頁面」,「行」,並使用「SORD」:

$limit = $this->getRequest()->getParam('rows', 10); 

,但我用得到什麼:

$params = $_REQUEST['filters'] 

$params = $this->getRequest()->getParam('sFilter'); 

我使用PHP,Zend和json。

我沒有發佈任何代碼,因爲我的疑問是一種通用的,但我會做,如果它需要。

我搜索了很多,並閱讀文檔,但我只是沒有看到它。我會感謝您的幫助,謝謝!

回答

1

那麼,我會回答我自己的問題只是爲了分享。我只是添加了'loadonce',它工作。

這是我的實際JavaScript代碼的版本:

$(document).ready(function() { 

var filtro = {"groupOp":"AND","rules":[{"field":"Col1","op":"eq","data":""}, 
            {"field":"Col3","op":"eq","data":""} 
            {"field":"Col4","op":"eq","data":""}]}; 

$("#lista").jqGrid({ 
    url:'/module/controller/json-action', 
    datatype: "json", 
    postData: { filters: JSON.stringify(filtro) }, 
    mtype: 'POST', 
    colNames:[, 'Col1', 'Col2','Col3','Col4'], 
    colModel:[ 
       {name:'N°',index:'ID', width:60, align:"center", hidden:true}, 
       {name:'Col1',index:'Col1', width:150, search:true, searchoptions: { sopt: ['eq'] } }, 
       {name:'Col2',index:'Col2', width:250, align:"left", search:false}, 
       {name:'Col3',index:'Col3', width:120, align:"left", search:true, searchoptions: { sopt: ['eq'] }}, 
       {name:'Col4',index:'Col4', width:60, align:"center", search:true, searchoptions: { sopt: ['eq'] }}] 
    , rowNum:10 
    , rowList:[10,20,30] 
    , pager: '#pager' 
    , sortname: 'ID' 
    , viewrecords: true 
    , sortorder: "desc" 
    , caption:"Listado de ejemplo" 
    , loadonce: true 
    , onSelectRow: function(id) { 
     $("#ID").val(id); 
     } 
    , ondblClickRow: function(id) { 
     $("#edit").submit(); 
    } 
}); 

$("#lista").jqGrid(
     'navGrid', '#pager', { edit:false, add:false, del:false }, 
     {},// settings for edit 
     {},// settings for add 
     {},// settings for delete 
     { multipleSearch:true/*activa la búsqueda avanzada*/, 
      closeAfterSearch:true, closeAfterReset:true, recreateFilter:true, 
      /*la función que define la búsqueda*/ 
      onSearch: function() {}//fin onSearch 
      , 
      //the search criteria that user selected before pressing find use below code: 
      onClose:function() { 
      }//fin onClose 

     } 
); 

});//fin document ready 

我所做的一切只是爲了增加「loadonce:真」。如果我刪除「loadonce:true」,網格將不再過濾。

相關問題