如图:
function loadDatagrid(){
$('#dg').datagrid({
url:'kkkkkk.do?method=queryyyyy',
method: 'POST',
title: '加载表格',
loadMsg: '正在加载,请稍后...',
striped: true,
fitColumns: true,
autoRowHeight: true,
singleSelect: true,
pagination: true,
rownumbers: true,
columns: [[
{field:'ck', checkbox:true },
{field: 'abcId', title: '号', width:80, align: 'center'},
{field: 'value', title: '最大服务数', width:80, align: 'center', editor:'numberbox'},
{field: 'createTime', title: '设置时间', width:100, align: 'center'},
{field : 'option', title : '操作', width : 60, align : 'center',
formatter:function(value,row,index){
var btn="<a class='link-button' href='javascript:editOne("+index+")'>编辑 </a>";
btn += " <a class='link-button' href='javascript:saveOne("+index+")'>保存 </a> ";
return btn;
}
}
]]
});
}
<%--编辑选中行内的最大服务数--%>
function editOne(index){
$('#dg').datagrid('beginEdit', index);
}
<%--保存编辑行--%>
function saveOne(index){
var row = $('#dg').datagrid('getSelected');
$('#dg').datagrid('endEdit', index);
var params = {
id : row.abcId,
max : row.value,
};
$.ajax({
url: "cccccc.do?method=sssssss",
data: params,
type: 'POST',
dataType: 'json',
timeout: 5000,
async: false,
error: function(){
alert('保存失败!');
return false;
},
success: function(json){
alert('保存成功!');
//重新加载该行的value单元格和createtime单元格
$('#dg').datagrid('updateRow', {index:index,
row:{paramValue: json.max, createTime: json.createTime}
});
}
});
}