I am using jqGrid
to show data in tabular format, using JSP
and Servlet
.
I have two dependent drop-downs to show.
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.
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")
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.