JChristian
JChristian

Reputation: 4170

How to suppress jqgrid from initially loading data?

I have a jqgrid in a modal popup that has data dependent on some input. I am doing this by setting the url option of the grid based on the input like below then showing the popup:

$(ContainerGrid.Grid).setGridParam({
    url: urlGetContainers + '?CRALineId=' + currentCRALineId
}).reloadGrid();

When the grid is first loaded on the screen, it isn't being displayed and no data needs to be retrieved until the modal popup is shown. Unfortunately, the jqgrid still tries to make a request to get data based on its url option.

I've tried using the hiddengrid property to hide/collapse the grid initially, which also keeps it from making a request for data. This didn't work, though, because I couldn't find a programmatic way show/expand the grid.

Is there any way to suppress the jqgrid from initially loading data?

Upvotes: 4

Views: 2394

Answers (2)

prograhammer
prograhammer

Reputation: 20590

I had a similar need as you when I needed my grids to load data only once the hash part of the URL is retrieved (the hash part of the URL determines what the filters are set to for my grid, then data can be loaded into the grid). So to prevent my grid from loading data on startup, this is what I did:

On grid setup:

$("#grid").jqGrid({
    url:"",
    mtype:"",
    ...

Later when I needed to actually load the data:

$("#grid").jqGrid("setGridParam",{datatype: "json", mtype: 'POST', url: myUrl, postData: params}).trigger("reloadGrid");

I also find it necessary to do a {postData: null} before the above reload to make sure post variables from a previous post are not included in future posts.

Upvotes: 0

The Matt
The Matt

Reputation: 6636

Initialize your grid in the 'Show' event of the modal popup. You can dynamically generate the jqGrid and insert it into the DOM, and then late-bind the data using the normal initialization code.

Upvotes: 3

Related Questions