Forum


19:23

04/12/2009

Hi:
I'm having an awkward problem here. I need to have a jqGrid return the results of a search query. What I need to do is, if the results are not what the user expected, they can specify a new search criteria and re run the query.
The problem is that for the second search to actually show up in the grid, I need an extra mouse click, I mean, the first search creates the grid and fills it fine. The second click would destroy (actually UnLoad) the grid but won't re-populate it and only the third click will show the results of the second search.
Here's my code:
var searchFor = $("#searchField").val();
var searchType = $('input[name="search_type"]:checked').val();
var g = $("#searchResults");
if ( g.jqGrid() )
g.GridUnload();
var project_id = $("#searchDialog #targetProject").val();
g.jqGrid(
{
datatype: "json",
height: 'auto',
autowidth: true,
url: '<?php echo url_for2('ajaxProjectSearch')?>',
postData: {
name: searchFor,
searchType: searchType
},
mtype: "POST",
colModel:[
{ name:'project_number', sortable: false, label: 'PSM', width: 20 },
{ name:'project_name', sortable:false, label: 'Project name', width: 70 }
],
viewrecords: true,
imgpath: gridimgpath,
rowNum: 10,
multiselect: false,
caption: "Search Results",
rowList:[10,20,30],
pager: 'searchResults_pager'
}
);
});
Thanks!
15:50

04/12/2009

I found a somewhat elegant solution to my problem. I believe the issue was in using the GridUnload method and re constructing the whole grid, which in my case, didn't make much sense to begin with. So I had to make a difference in whether the grid was already constructed or not (which was actually the hardest step). I used this test in order to see wether the grid was constructed or not:
if ( typeof(g[0].grid ) == "undefined" )
I don't know if there's a better way to accomplish this, if not, I think it'd be a good addition to the jqGrid plugin. Anyway, what I did in the else part of this if is change the postData and then reload the grid (but without unloading it first):
{
g.setGridParam( {
postData: {
name: searchFor
}
} );
g.trigger("reloadGrid");
}
And that was it!. Perhaps another good addition could be a method to reload the grid with new post parameters or to add some parameters to the trigger("reloadGrid") method...
Anyway, thanks to all and hope this helps somebody!
Most Users Ever Online: 715
Currently Online:
159 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66