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
After calling reloadGrid pager stops sending paging information.
08/01/2014
17:10
Avatar
mscherzer
Member
Members
Forum Posts: 3
Member Since:
08/01/2014
sp_UserOfflineSmall Offline

Hi,
I have a hit a stump in my attempt to integrate jqGrid hopefully someone can point me in the right direction.

When I first load my html page everything works as expected until I reload the grid with: trigger('reloadGrid'). After the reload the pager stops sending any of the paging information in subsequent requests.

Anyone got any ideas what I am doing wrong? Do I have to also somehow reinit the pager?

Quick summary of what I am doing:

1) Need to communicate with our server only using POST requests.
2) Our search form can not be the one provided by the jqGrid search functionality.
3) When a user clicks the search button on our search form, the form fields are copied to a struct of name:value pairs which are then added to the postData option after which we call trigger('reloadGrid').

Code snippet:

data =
{
    API_FUNCTION:"DO_MY_SEARCH",
    hint:"OPEN_ITEMS",
    userID:$("#supplierID").val(),
    description:$("#description").val()
};
$('#resultGrid').setGridParam({postData:data});
$('#resultGrid').trigger('reloadGrid');

Everything works as expected except the "Pager" which breaks as soon as the grid is reloaded. Clicking the pager buttons still request data from the server with the correct search fields just without any of the pager data. (page, rows etc.) As stated before when the grid is first initialised the pager passed all its fields as exepected.

Anyone got any ideas?

cheers

Marcel

09/01/2014
05:39
Avatar
mscherzer
Member
Members
Forum Posts: 3
Member Since:
08/01/2014
sp_UserOfflineSmall Offline

I have now worked around this issue.

What I think is was happening is that when I set the postData option I was overriding the fields set by the pager.

As a work around I build a little helper method that grabs the existing postData that also contains the pager fields and then I just appends my data to it.

This now works for me but I can't help wondering if there is not a neater way to do this?

The following code may or may not be usefull to someone else trying to do the same thing.

This is the helper method that turns the fields in an external form into an object that can be passed to the postData option.

The method expects a jquery selector to find the form that is to be posted on every request. The method is also passed an existing postData object that is merged with the values retrieved from the form fields.

+++++++++++++++++++++++++++++++++++++++++++++++

function objectFromForm(selector,extraData)
        {
            var source,target;
            
            source = $(selector).serializeArray();
            target = {};
            
            /* Turn the form into an object. Values for duplicate key names are added as a comma seperated values. */
            $.each(source,function(i,item)
            {
                var key,value;
                key = item.name.toLowerCase();
                value = item.value;
                if(key in target)
                {
                    value = target[key] + "," + value;
                }
                
                target[key] = value;
            });
            
            /* Append extraData to form (extraData does NOT override form fields.) */
            $.each(extraData,function(key,item)
            {
                if(!(key in target))
                {
                    target[key] = item;
                }
            });
    
            return target;
        }

+++++++++++++++++++++++++++++++++++++++++++++++

The following code is then added to the beforeRequest handler. Now after every request the current form is also submitted including all the relevant paging information. One stupid thing in this implementation is that checkboxes and other form elements that don't get posted when they are unchecked must be manually removed. So changes to the form require changed to this code. 🙁

beforeRequest:function()
            {
                var postData, formData;
                
                /* We need to do this to persist the paging data accross requests. */
                postData = $('#resultGrid').getGridParam("postData");                
                
                /*
                We need to remove any form elements that are not submitted if empty. checkboxes, radio fields etc.
                Without this code any set values will never be unset on subsequent requests.
                */
                delete postData["purchaseorderid"];
                formData = objectFromForm("#frmFilter",postData);
                $('#resultGrid').setGridParam({postData:formData});
                
            }

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
41 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