Reputation: 251
I have a javascript function in which i receive a value of drop down. function is below:
function SetTemplateId(id) // this method is called on drop down change event
{
templateId=id; // template id is global variable
showjqgrid(); //this method show the Jqgrid
}
ShowJqgrid method is below
function showjqgrid()
{
$("#grid").jqGrid({
datatype: 'json',
url: '/Home/DynamicGridData?id='+templateId,
........
}
jqgrid is works fine but the problem is when "setTemplateid" function is called first time it works fine and data is show correctly and after first time when i change drop down value the "setTemplateId" function is called(i checked by alert()) and showgrid is also called but the URL is not invoked. If i destroy jqgrid in "setTemplateId" function then jqgrid is not shownn. If i reload jqgrid then also the data show only first time. I debuged it. Only first time action method is called. After that its not called. What is the problem?
Upvotes: 0
Views: 135
Reputation: 221997
The reason is very easy. The function showjqgrid
convert empty table <table id="grid"></table>
in relatively complex structure of divs and tables. After that jqGrid makes request to the url
.
So you have two main options (alternatives) to fix the problem:
GridUnload
method as the first line of showjqgrid
. It will destroy the complex structure of divs and tables created previously and reduce there to one empty <table>
.url
parameter using setGridParam
and then trigger reloadGrid
which will update the content of the grid holding the outer part unchanged.Additionally I would recommend you to read the old answer which shown how to use postData
parameter of jqGrid where the properties are defined as functions. I suppose that templateId
which you use as the value of id
parameter of url
will be evaluated in some way inside of dropdown change event. So you can consider to do this inside of the function defined inside of postData.id
. In the case you could use url: '/Home/DynamicGridData
and the part ?id='+templateId
will be appended by jqGrid.
Upvotes: 1