1

I am using jqGrid to show data in tabular format, using JSP and Servlet.

I have two dependent drop-downs to show.

  1. Show State
  2. Show City

Following is relevant code:

colNames:['User ID', 'Name','State','City'], 
colModel:[
{name:'USERID',index:'USERID',....},
{name:'NAME',index:'NAME',....},
{
name:'STATE',
index:'STATE',
width:125,
sortable:true,
edittype:"select",
editoptions: {
    maxlength: 15,
    dataUrl: 'MYServlet?action=getState',
    dataEvents :[{ 
        type: 'change',
        fn: function(e) {
            var thisval = $(e.target).val();
            $.post('MyServlet?action=getCity='+thisval,
            function(data){
                var res = $(data).html();
                $("#STATE").html(res);
            });
        }
    }]
}
},
{
    name:'CITY',
    index:'CITY',
    width:125,
    sortable:true,
    editable:true,
    edittype:"select",
    editoptions:{maxlength: 50 , value: 'Select:Select'}
}
],

Above code is working fine for dependent drop-downs. Now I want to pass USERID with datUrl in editoptions of STATE column. like

dataUrl: 'MYServlet?action=getState&userid='+userid

But I am not able to get USERID in dataUrl.

So any suggestions will be appreciated.

Bhushan
  • 6,151
  • 13
  • 58
  • 91

1 Answers1

1

I suggested some extensions of dataUrl which are now part of jqGrid. It's usage of postData property of editoption defined as function (see the answer) or usage of dataUrl as function directly (see here and here). The first feature is included in jqGrid 4.4.2, but the second is included after 4.5.2 was released. So I recommend you to use postData as function.

What you need to do is adding postData property to editoptions of STATE column in the form

editoptions: {
    dataUrl: "MYServlet",
    postData: function (rowid) {
        return {
            action: "getState",
            userid: $(this).jqGrid("getCell", rowid, "USERID")
        };
    }
}

If the values of USERID column is unique and you use key: true then rowid are already the same value as the value of USERID column. In the case you can simplify the above code and use rowid directly instead of $(this).jqGrid("getCell", rowid, "USERID").

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Can you help me for this Question? http://stackoverflow.com/questions/23534548/how-to-load-data-in-jqgrid-column-in-jsp-from-database – sathya May 08 '14 at 09:54