Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
Can't get a second request in place
16/03/2010
19:23
Avatar
mchojrin
Member
Members
Forum Posts: 11
Member Since:
04/12/2009
sp_UserOfflineSmall Offline

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:

$("#searchButton").click(function(){
    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!

18/03/2010
15:50
Avatar
mchojrin
Member
Members
Forum Posts: 11
Member Since:
04/12/2009
sp_UserOfflineSmall Offline

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:

var g = $("#searchResults");
    
    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):

else
    {
        g.setGridParam( {
            postData: {
            name: searchFor           
             }
        } );
        g.trigger("reloadGrid");
    }

And that was it!Smile. 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!

Forum Timezone: Europe/Sofia

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.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information