Need to override Search Filter url param (_search) in jgrid the jquery plugin?
Hi I have created a user message page with this plugin. The grid will show the user inbox and the user outbox(sent) messages. here's a little code:
jQuery(document).ready(function() {
//...some stuff
currentURL = function() {
return 'json_member_mail.php?task='+ currentBox;
//where current box is either inbox or outbox
}
//... alot of stuff
myGrid = jQuery("#list").jqGrid({
url:currentURL(),
datatype: 'json',
mtype: 'GET',
// even more stuff ....
}).jqGrid('navGrid','#pager',
{
the lil stuff....
search:true,
//the dialog...
}
// the dialog form editing whatever...
);//grid
});//document.ready
so then when the user clicks on outbox something like this happens:
jQuery("#list").jqGrid('setGridParam',{ url:currentURL(), postData:{lrt:lastReloadTime} }).trigger("reloadGrid"); //where current URL has the GET param task=outbox
it working all great until I use my search filters. for example I search for the messages sent from the user 'foo' and it's all good but when I click on outbox it will still try to show me messages sent by the user 'foo' but I want the search filters to be reset.
I tried loading the search dialog on document ready and closing it i开发者_开发问答mmediately to get the filter().reset and all that but it doesn't work :the-built-in-search-filter-box
myGrid.trigger('reloadGrid'); has the same behaviour as well
.jqGrid('setGridParam',{ url:currentURL(), postData:{_search:'false'} }).trigger("reloadGrid");
would fix my problem but it won't override the _search param.
any generous suggestions?
I recommend you to use no function call as avalue of the url
parameter. The value of the parameter will be caclulated only once during the grid initialization. Instead of that you can use
url: 'json_member_mail.php',
postData: {
task: function() {/* return currentBox based on criterias which you have */},
lrt: lastReloadTime
}
If needed you can make the property lrt
also as a function.
If some property of postData
are functions the function will be called on any ajax request. So you can use really actual value of the currentBox
on searching, paging, sorting or page reload.
If you need reload jqGrid you will no more need to change url
or postData
and you can just call trigger("reloadGrid")
only.
lol, So I made one of those stupid mistakes... where in the original message I say "// the dialog form editing whatever..." I made a mistake yeah I didn't even bother to write that part on here so what I had there was:
}).jqGrid('navGrid','#pager',
{
edit:false,
add:false,
del:false,
search: true,
refresh:true,
refreshtext:"Refresh",
searchtext:"Search"
},
{},//add
{}, //edit
{}, //delete
{}, <---instead of putting search options on this line
{ <----I was putting it here on this line
overlay:false,
closeOnEscape:true,
afterShowSearch:... ,
} /* allow the view dialog to be closed when user press ESC key*/
);//grid
however I realized that after I fixed my problem with a hack when I saw the overlay:false was not working and there was still a jQuery UI overlay for search...
what I did might be helpful somehow to someone who reads this one day so what I did was:
there is a get parameter nd that is a Unix Timestamp(POSIX) but in miliseconds (javascripts implementation) unlike php and mysql and most unix stuff (which is in seconds). I also sent a timestamp of the last time any of the navigation links where clicked:
lastReloadTime = new Date().getTime() ;
jQuery("#list").jqGrid('setGridParam',{
url:currentURL(),
postData:{lrt:lastReloadTime
}
then in my php file that generates the json data:
$searchOK = 1;
if($_GET['_search']=='true') {
if( isset($_GET['lrt']) ){
//so here I check to see if the main mail links have been clicked at all
//from the time of the first page load
//if not then its all good but if it has check for the time
if( ( ($_GET['nd']/1000)-($_GET['lrt']/1000) ) < 1) $searchOK=0;
}
if($searchOK){ //you can do search since it might be going through pages of a search result
精彩评论