jqGrid - determine whether find or reset clicked in search window?
We are using jqGrid searching.. how can you determine if a user has clicked Search, Reset, or has closed the search window?
There is an onClose
event but it doesn't seem to have any 开发者_运维知识库parameters that indicate the action.
??
The answer on your question is depend on how you want to use the information. If you want that your callback function will be called you can use beforeShowSearch together with onClose
:
$("#list").jqGrid('navGrid', '#pager',
{edit: false, add: false, del: false, search: true, refresh: true},// options
{}, // settings for edit
{}, // settings for add
{}, // settings for delete
{beforeShowSearch: function(form){
$('.ui-search',form).click(function(){
alert("in onSearch");
});
$('.ui-reset',form).click(function(){
alert("in onReset");
});
},onClose: function(data){
alert("in onClose");
}
} // search options
);
You should take in consideration, that your onSearch
and onReset
functions will be called after the main event handler, so the request to search or the request to reset is already sent. If you need to have the information before the search or reset the usage of beforeRequest
request seems me very good. If you need to have search rules you can use $("#list").jqGrid('getGridParam','postData')
or just $("#list")[0].p.postData
. The postData
has searchField
, searchOper
and searchString
(in case of Single Searching) or filters
(in case of Advanced Searching) set. In case of "Reset" the parameters are empty: "".
As a workaround, we're using the beforeRequest
grid event.
The f
variable will be false if no searching is being performed, will be true otherwise:
beforeRequest: function() {
var m = $("#status-header").is(":visible");
var f = $("#list").getPostDataItem('_search');
if ((m && !f) || (!m && f)) {
$("#status-header").toggle('highlight',{},500);
}
},
精彩评论