I'm using inline editing and formatted delete/edit action buttons for local grid add/edit/delete after loading data from server.
I want to know how to save the last edited row when using formatted delete button to delete another row in jqgrid.
I have found the similar solution provided by Oleg.
(the similar answer) But it doesn't work for formatted delete button because the lats selected row has been restored before onSelectRow is trigger.
I'm new in jqGrid and this is my first question in Stackoverflow. Please help and thanks in advance.
following is my code:
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
},
}
);
and 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();
}
}