0

Here is the code of my dropdown.

  {
 name: 'ClassId', index: 'ClassId', align: 'center',editable: true, edittype: 'select',
 editoptions: {
 dataUrl:'@Url.Action("GetAllClasses", "Class", new { Area = "Curriculums"})',
 buildSelect: function (data) {
                     var response, s = '<select>', i;
                     response = jQuery.parseJSON(data);
                     //s += '<option value="0">--Select Class--</option>';
                     if (response && response.length) {
                         $.each(response, function (i) {
                      s += '<option value="' + this.Id + '">' + this.ClassName + '</option>';
                      });
                     }
                     return s + '</select>';
                 }
             }
          },

I am using form edit.I am reloading grid after insert.But the problem is after inserting data when I try to add another one my dropdowns are getting refreashed.I want that the dropdown selected value will be previously selected value.I don't want to change dropdown selected value on the second add.

Mir Gulam Sarwar
  • 2,588
  • 2
  • 25
  • 39

1 Answers1

1

The most simple way to prevent reloading of data from dataUrl could be setting Cache-Control HTTP header in the server response. Setting of Cache-Control: max-age=60 in the server response for example will prevent reloading of data from the server during 60 sec. In case of ASP.NET MVC you can use CacheControl attribute for example (see Duration and Location properties).

One more alternative would be dynamical setting editoptions.value instead of usage editoptions.dataUrl. For example one can include the information needed for building editoptions.value as an extension of the standard response of the server for filling the grid. One can use beforeProcessing to process the part of the data. You will find the corresponding examples in the following cold answers: this one, this one, this one, this one, this one and other. The answer describes in short one of the the possible scenario to create full dynamic grid.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • thanks you very much.We are so lucky that you are on SO for help – Mir Gulam Sarwar Feb 19 '14 at 15:33
  • @janina: Take a look in [the answer](http://stackoverflow.com/a/21901410/315935). It's about the same subject and describes different implementation options. – Oleg Feb 20 '14 at 07:52
  • this is working but dropdown selected value doesn't persist, it is getting changed on second Insert – Mir Gulam Sarwar Mar 17 '14 at 12:50
  • @janina: Sorry, but I have no idea what you mean. I posted you references to many old answers with many **alternatives**. Which one you use? You wrote about "second Insert". What "insert" you mean? What will be changed? – Oleg Mar 17 '14 at 17:27
  • Suppose I selected Class: Nine from my Dropdown and clicked Submit or Close Button.Now again if I click Add Button I can see that in my class dropdown, Class:Nine is not selected Now.It is now as it was first time loaded.How can I make the dropdown to persist the item which was previously selected?Thanks – Mir Gulam Sarwar Mar 17 '14 at 17:38
  • I used both editoption.value and editoption.daturl but neither worked on the above issue. – Mir Gulam Sarwar Mar 17 '14 at 17:41
  • @janina: 1) If you defined `editoption.value` then `editoption.dataUrl` will be ignored. 2) If you knows that adding of new row can modify possible values of your `editoption.value` then you can use for example [afterSubmit](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:form_editing#events) callback of form editing to update `editoption.value` with respect of `setColProp`. – Oleg Mar 17 '14 at 17:48
  • can setColProp will help here? What will be its job here? – Mir Gulam Sarwar Mar 17 '14 at 18:07
  • @janina: `setColProp` helps to modify `colModel` parameters. Don't forget to use `recreateForm: true` option of form editing. – Oleg Mar 17 '14 at 18:12