我现在的问题是在编辑该行时尝试发送该行的 ID ( editable: false
)。
例如,我有一个网格,其中包含列 userid( editable: false
)、用户名( editable: true
)、名字( editable: true
)、姓氏( editable: true
)。编辑行时,网格仅发送参数用户名、名字和姓氏。在服务器端,我需要用户 ID 来知道我将这些新值应用到哪个用户。
editUrl 看起来像:
editurl : CONTEXT_PATH+'/ajax/admin/savePart.do?category=1',
谢谢
这是完整的代码:
$.jgrid.useJSON = true;
//http://www.trirand.com/jqgridwiki/doku.php?id=wiki%3Acommon_rules
$(document).ready(function() {
//alert(CONTEXT_PATH);
var lastsel;
jQuery("#rowed3").jqGrid(
{
url : CONTEXT_PATH+'/ajax/getPartesByCategory.do?catid=<s:property value="categoryId" />',
//url : '/autoWEB/text.html',
datatype: "json",
ajaxGridOptions: { contentType: "application/json" },
jsonReader : {
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems: false
},
headertitles: true,
colNames : [ 'ID', 'Pieza', 'Disponible'],
colModel : [ {
name : 'piezaId',
index : 'piezaId',
align : "right",
width : 50,
editable : false,
required : true
}, {
name : 'descripcion',
index : 'descripcion',
width : 390,
editable : true,
required : true
}, {
name : 'disponible',
index : 'disponible',
width : 80,
editable : true,
edittype : 'select',
editoptions:{value:"0:No;1:Si"},
required : true
} ],
rowNum : 20,
rowList : [ 20, 40, 60, 80 ],
pager : '#prowed3',
sortname : 'piezaId',
postData: {piezaId : lastsel},
mtype:"POST",
viewrecords : true,
sortorder : "desc",
onSelectRow : function(id) {
if (id && id !== lastsel) {
jQuery('#rowed3').jqGrid('restoreRow', lastsel);
jQuery('#rowed3').jqGrid('editRow', id, true);
lastsel = id;
}
},
editurl : CONTEXT_PATH+'/ajax/admin/savePieza.do?categoria=<s:property value="categoryId" />',
caption : "Piezas"
});
jQuery("#rowed3").jqGrid('navGrid', "#prowed3", {
edit : false,
add : false,
del : false
});
})
最佳答案
在 onSelectRow 回调中,您可以将 editUrl 修改为您想要的任何内容,包括传入您需要的 ID。
$("#rowed3").jqGrid('setGridParam', {editurl:'whatever/url/you/need/with/the/id'});
jqGrid 将为您添加所有其他必要的参数到该 editurl。
关于javascript - 向 JQgrid 上的 editurl 发送附加参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3176157/