我正在使用jqgrid 4.8.2。如果用户单击一行,我想保存以前选择的行并在编辑模式下显示当前行。我使用了previous answers中的代码但无法使用此功能。经过一些调试并查看jqgrid的源代码后,看起来saveRow不会触发,因为前一行的'editable'属性立即设置为0. jqgrid源代码中有一个子句在保存之前查找该属性行:
editable = $(ind).attr("editable");
o.url = o.url || $t.p.editurl;
if (editable==="1") {....saveRow occurs...}
有关如何解决这个问题的任何建议吗?
var editingRowId;
var myEditParam = {
keys: true,
extraparam: {activityID: aID},
oneditfunc: function (id) { editingRowId = id; },
afterrestorefunc: function (id) { editingRowId = undefined; },
aftersavefunc: function (id) { editingRowId = undefined; }
};
var myGrid = jQuery("#spend_grid").jqGrid({
url: parentGridURL,
mtype: "POST",
datatype: "json",
postData: {filters: myFilters},
gridview: false, //added for IE
altRows: true,
emptyrecords: 'NO PAYMENTS FOUND',
editurl: savePaymentURL,
onSelectRow: function (id) {
console.log('id=' + id + ' editingRowId =' + editingRowId);
var $this = $(this);
if (editingRowId !== id) {
if (editingRowId) {
// save or restore currently editing row
console.log('should be saving ' + editingRowId);
$this.jqGrid('saveRow', editingRowId, myEditParam);
console.log('done saving');
}
$this.jqGrid("editRow", id, myEditParam);
}
},
search: true,
sortname: lastSortName,
sortorder: lastSortOrder,
page: lastPage,
pager: jQuery('#report_pager'),
rowNum: lastRowNum,
rowList: [10,20,50,100],
viewrecords: true,
clearSearch: false,
caption: "Payments",
sortable: true,
shrinkToFit: false,
excel: true,
autowidth: true,
height: 300,
subGrid: true, // set the subGrid property to true to show expand buttons for each row
subGridRowExpanded: showChildGrid, // javascript function that will take care of showing the child grid
colModel: [
{ label: 'Payment ID',
name: 'PAYMENTID',
index: 'p.paymentID',
key: true, width: 75
},...// removed for brevity
{name : 'actions',
label: 'Actions',
index: 'formAction',
formatter:'actions',
width: 75,
search:false,
formatoptions: {
keys: true,
editbutton: false,
delOptions: { url: savePaymentURL }
}
}
]
}).inlineNav('#report_pager',
// the buttons to appear on the toolbar of the grid
{
restoreAfterSelect: false, // *****SOLUTION******
save:false,
edit: false,
add: false,
cancel: false
});
答案 0 :(得分:0)
找到问题的解决方案。在检查了jqgrid源代码后,我发现restoreAfterSelect:true是inlineNav
的默认设置。我添加了restoreAfterSelect: false
,现在上一行保存了。