我想使用自定义删除按钮删除行。我正在使用以下代码段:
var cellValue;
var id;
$gvRoleDetails = jQuery("#gvRoleDetails");
$gvRoleDetails.jqGrid({
datatype: 'local',
colNames: ['Role', 'Module', 'Function', 'AppRoleID', 'AppID', 'AppModuleID', 'AppFncID', 'PermCreate', 'PermEdit', 'PermView', 'PermDelete', 'PermAuth', 'PermCancel','RoleOrgID','Remove'],
onSelectRow: function (id) {
var rowData = jQuery(this).getRowData(id);
cellValue = rowData['AppFncID'];
},
colModel: [
{ name: 'Role', index: 'Role', width: 200 },
{ name: 'Module', index: 'Module', width: 200 },
{ name: 'Function', index: 'Function', width: 200 },
{ name: 'AppRoleID', index: 'AppRoleID', hidden: true },
{ name: 'AppID', index: 'AppID', hidden: true },
{ name: 'AppModuleID', index: 'AppModuleID', hidden: true },
{ name: 'AppFncID', index: 'AppFncID', hidden: true, key: true },
{ name: 'PermCreate', index: 'PermCreate', hidden: true },
{ name: 'PermEdit', index: 'PermEdit', hidden: true },
{ name: 'PermView', index: 'PermView', hidden: true },
{ name: 'PermDelete', index: 'PermDelete', hidden: true },
{ name: 'PermAuth', index: 'PermAuth', hidden: true },
{ name: 'PermCancel', index: 'PermCancel', hidden: true },
{ name: 'RoleOrgID', index: 'RoleOrgID', hidden: true },
{
name: 'Remove', index: 'AppFncID', sortable: false,
formatter: function (rowId, cellval, colpos, rwdat, _act) {
var rowInterviewId = colpos.AppFncID.toString();
return '<input type="button" id="' + rowInterviewId + '" value="Remove" class="btn" onClick = "RemoveData(this)" />';
}
}
],
rowNum: 10,
gridview: true,
autoencode: true,
height: "auto",
pager: '#jQGridDemoPager',
sortname: "Role",
multiselect: false,
viewrecords: true,
sortorder: "desc",
});
RemoveData函数用于传递选定的行值以进行删除:
function RemoveData(rowData) {
alert(rowData);
}
如何使用函数RemoveData(rowData)使用相同的结构删除行?
答案 0 :(得分:0)
在rowid变量赋值后,我已传递rowData.id进行删除,然后运行良好。
function RemoveData(rowData) {
var rowid = rowData.id;
var su = $('#gvRoleDetails').jqGrid('delRowData', rowid);
$('#gvRoleDetails').trigger('reloadGrid');
}