1.数据网格加入双击事件
onDblClickCell : onDblClickCell
2.双击触发行编辑
function onDblClickCell(index){
$('#grid').datagrid('selectRow', index).datagrid('beginEdit', index);
editIndex = index;
}
3.调用修改方法、传值到后台
function editFun(ID){
if (endEditing()){
var rowss = $('#grid').datagrid('getChanges');//获取到所有修改后的值
if(rowss.length==0){//如果等于0提示没有任何改变
$.messager.alert('提示', "没有任何改变");
}else{
$.post(sy.contextPath + '/gzsz/regulation!updateRegulation.sy', {
"rowss" : JSON.stringify(rowss[0]),//修改后的值转成Json格式传到后台
"id" : ID//修改行的ID
}, function(result) {
parent.$.messager.alert('提示', result.msg, 'info');
grid.datagrid('reload');
}, 'json');
}
}
}
4.后端代码
public void updateRegulation(){
Json json = new Json();
Map<String, Object> map = (Map<String, Object>) JSON.toJSON(regulationDTO);
try {
String rowss = getRequest().getParameter("rowss");
JSONObject object = JSONObject.parseObject(rowss);
String is_parallel = object.getString("IS_PARALLEL");
map.put("is_parallel", is_parallel);
regulationServiceI.updateRegulation(map);
json.setMsg("更新成功!");
json.setSuccess(true);
} catch (Exception e) {
json.setMsg("更新错误!");
log.error(e.getMessage(), e);
}
writeJson(json);
}