0

In my MVC application I am facing very strange issue with jquery dialogs. I am using multilevel dialog for this application; wherein at 1st level dialog there will be jqGrid displaying records & provides link column to manipulate records in 2nd level dialog.

A dialog containing small form to manipulate data can be opened by using link column from jqGrid. There is an issue with pre-populating this form data when the link is clicked; & which occurs on random time interval. When I open this form for editing any record from jqGrid the data pre-populated is from previously opened record for editing. Then if close this dialog & try to open same record for editing 2nd time it will show me correct pre-populated data. And once this problem occurs then after this continues to exist till we refresh base page in browser. If I check response received with the current ajax call for loading data in dialog form using firebug; I see that data returned fro server is correct but data displayed in form is wrong which is from previously opened record of jqGrid. You can see this in screenshot below

see the screenshot below enter image description here

In the grid behind the topmost dialog the last column having edit icon is the link column to open the top dialog having the form with issue. this column contains the data as well [May be date or text] which will be send to opened form as parameter for editing. as can be seen in the picture the 2nd record selected in grid is having date as 11/26/2013 & html response I got from ajax request generated by clicking respective link is as per the functionality. But the opened dialog is showing the date of first record which was edited previously before current editing.

This is a kind of data caching problem; I have tried including following meta tag on the respective 1st & 2nd level popup views

<meta http-equiv='cache-control' content='no-cache'>
<meta http-equiv='expires' content='0'>
<meta http-equiv='pragma' content='no-cache'>

by which I thought the the problem was resolved; but it didn't. As per my observation It has just reduced frequency of occurance of this issue Not sure

I hope this description is clear enough to understand the issue.

Shaggy
  • 315
  • 2
  • 9
  • 23

1 Answers1

0

It's difficult to find the reason of the described problem without looking into the code and without debugging of the problem. So I try just guess.

First of all I strictly recommend you to use always recreateForm: true option of form editing. Without usage of the option jqGrid hide Edit dialog on closing and show it back on the next editing. jqGrid refills the fields of the form, but in case of usage of recreateForm: true jqGrid recreate the full editing dialog every time.

The next possible problem could be id duplicates on the page. jqGrid set id attribute on every jqGrid row and on every column of editing form. If you have more as one grid on the page it's possible that you use native ids from the database. The problem is that native id from the database table are unique only inside of one table. If you display information from different tables ids can be the same. One more example is displaying a grid with based information ad the second grid with details information. In the case the same id could be used twice too. So I recommend you to use idPrefix option in every grid. For example if you use idPrefix: "a" in one grid and idPrefix: "b" in another grid then the id 1 returned from the server will be assigned as rowid "a1" in the first grid and as rowid "b1" in the second grid. If the results of row editing will be send back to the server the id prefix will be cut and the server will see the original id=1.

One more possible origin of id duplicates are in the fields of editing form. The id of the field of the editing form uses id the same as the column name. So if you have more as one grids on the page with the same name property in both grids you could have id duplicates. So the recommendation: use unique name attributes for all grids. If you use repeatitems: false (named fields in the input data) then you can use jsonmap property of jqGrid which corresponds to the fields of JSON input data and use any free name value of columns in the grid. In the way you can easy construct grids having unique name in colModel. I hope that you understand the construct which I suggest.

I recommend you first of all to try to use recreateForm: true option adding the line

$.extend($.jgrid.edit, {recreateForm: true});

at the beginning of your code. It will set default value for recreateForm to true. After that you should repeat your tests.

It setting of recreateForm: true will not fix the problem you can include idPrefix with unique value ("a", "b", "c", ... or "g1_", "g2_", "g3_", ...). After that you should repeat your tests. Making unique name in colModel you can make at the last step only if previous steps failed.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Hi Olege, thanks for your replay. I'd like you to brief you about jqgrid usage on the form. I have just used jqGrid to display records. & for last column I have used formatter option with the use of which I am creating hyperlinks in last column on whose click I am opening separate jquery dialog. I am not using in build grid editing functions. – Shaggy Dec 05 '13 at 09:33
  • @Shaggy: You can find ma email at the end of "About Me" information on stackoverflow: oleg.kiriljuk@ok-soft-gmbh.com. You can try to call `"destroy"` method of jQuery UI Dialog and then call jQuery `remove` to remove the `
    ` used by the dialog (see [here](http://stackoverflow.com/a/2864783/315935)). I hope that after that opening of the dialog at the second time will work exactly as at the first time.
    – Oleg Dec 05 '13 at 10:41