我在从服务器加载数据后使用内联编辑和格式化删除/编辑操作按钮进行本地网格添加/编辑/删除。
我想知道在使用格式化的删除按钮删除jqgrid中的另一行时如何保存最后编辑的行。
我找到了Oleg提供的类似解决方案。
(the similar answer)但它对格式化的删除按钮不起作用,因为在onSelectRow触发之前已经恢复了所选的行。
我是jqGrid中的新手,这是我在Stackoverflow中的第一个问题。请提前帮助和谢谢。
以下是我的代码:
var $grid = $("#dataGrid");
$("#dataGrid").jqGrid({
url:"......",
datatype: "json",
shrinkToFit:true,
height: "100%",
autowidth: true,
gridview: true,
editurl:'clientArray',
colNames:['action', 'isPublic', 'no', 'name'],
colModel:[ {name:'action',width:50,fixed:true,sortable:false,formatter:'actions',
formatoptions:{ delOptions: formatDelOptions,
onEdit:function(id){
if (typeof (lastSel) !== "undefined" && id !== lastSel) {
cancelEditing($grid);
}
lastSel = id;
}
}},
{name:'isPublic', width:80, align:'center',fixed:true,sortable:false, editable:true, formatter:'checkbox', edittype:'checkbox', editoptions:{value: "Y:N", defaultValue:"N"}},
{name:'no',width:80, align:'center', editable:true, editoptions:{maxlength:6}, editrules:{required:true}},
{name:'name', width:120, align:'center', editable:true, editoptions:{maxlength:10}, editrules:{required:true}},
],
caption :"Data",
rowNum: 10,
rowList: [10, 20],
pager:"#dataGridPager",
recreateForm:true,
viewrecords: true,
rownumbers:true,
rownumWidth: 35,
loadonce: true,
emptyrecords: "<font color='red'>no data</font>", //when viewrecords is set to true
onSelectRow: function(id) {
if (typeof (lastSel) !== "undefined" && id !== lastSel) {
cancelEditing($grid);
}
lastSel = id;
}
}).jqGrid("setGridParam", {page:0}).trigger("reloadGrid")
.jqGrid('navGrid', "#dataGridPager",{edit:false,add:false,del:false,search:false,refresh:false,
beforeRefresh: function () {
$(this).jqGrid("setGridParam",{datatype: "json"});
}
})
.jqGrid('inlineNav',"#dataGridPager",
{
edit: false, //editicon: "ui-icon-pencil",
add: true, //addicon:"ui-icon-plus",
save: true, //saveicon:"ui-icon-disk",
cancel: true, //cancelicon:"ui-icon-cancel",
addParams : {
position :"last",
addRowParams : inlineEditOptions
},
}
);
和cancelEditing:
function cancelEditing(grid){
var lrid;
if (typeof lastSel !== "undefined") {
grid.jqGrid('restoreRow', lastSel); //('saveRow', lastSel, false, 'clientArray')
lrid = $.jgrid.jqID(lastSel);
$("tr#" + lrid + " div.ui-inline-edit, " + "tr#" + lrid + " div.ui-inline-del").show();
$("tr#" + lrid + " div.ui-inline-save, " + "tr#" + lrid + " div.ui-inline-cancel").hide();
}
}