[英]Custom Delete Function in jqGrid
I am trying to customize the delete function in jqGrid. 我正在尝试自定义jqGrid中的删除功能。
I have enabled the delete button on the grid 我已启用网格上的删除按钮
$("#myGrid").jqGrid('navGrid', '#pager',
{ add: true, addtitle: 'Add Customer',
edit: true, edittitle: 'Edit Customer',
del: true, deltitle: 'Delete Customer',
refresh: true, refreshtitle: 'Refresh data',
search: true, searchtitle: 'Apply filters',
addfunc: addForo, editfunc: editForo,
cloneToTop: true
},
{}, // default settings for edit
{}, // default settings for add
{}, // default settings for delete
{ closeOnEscape: true, multipleSearch: true, closeAfterSearch: true }, // search options
{} // default settings for view
);
then I have added (thanks to this post ) the following code 然后我添加了(由于这篇文章 )以下代码
$("#bDelete").click(function () {
// Get the currently selected row
toDelete = $("#myGrid").jqGrid('getGridParam', 'selrow');
$("#myGrid").jqGrid(
'delGridRow',
toDelete,
{ url: '/Foro/Delete/' + toDelete, mtype: 'post', reloadAfterSubmit: false }
);
});
Now when I click on the delete button a dialog is shown asking for delete confirm. 现在,当我单击删除按钮时,将显示一个对话框,要求删除确认。 But if I click on the delete button I will get the following error message
但是,如果我单击删除按钮,我将收到以下错误消息
Where am I wrong? 我哪里错了?
If I understand you correct you want to modify the url
used to delete of row so that the id of the row will be a part of the url
. 如果我理解的正确,那么您想修改用于删除行的
url
以使该行的id成为url
的一部分。 You can do this much easier: 您可以更轻松地做到这一点:
$("#myGrid").jqGrid('navGrid', '#pager',
// define navGrid options and paraneters of Edit and Add dialogs
{ // now define settings for Delete dialog
mtype: "POST", reloadAfterSubmit: false,
onclickSubmit: function(rp_ge, postdata) {
rp_ge.url = '/Foro/Delete/'+ postdata;
},
serializeDelData: function (postdata) { return ""; }
},
// search options
// ...
);
With respect of onclickSubmit
we can modify the url
and defining of serializeDelData
we can clear the body of the "POST" message. 关于
onclickSubmit
我们可以修改url
并定义serializeDelData
我们可以清除“ POST”消息的正文。 I peronally mostly use RESTfull services on the server side and use mtype: "DELETE"
. 我通常在服务器端使用RESTfull服务,并使用
mtype: "DELETE"
。 In the case to clear of the body is really needed. 在这种情况下,真正需要清除身体。
One more option is to use delfunc
like you already use editfunc
and addfunc
. 另一个选择是使用
delfunc
就像您已经使用editfunc
和addfunc
。 In the most cases the usage of such function is not really needed and one can implement the same in other way. 在大多数情况下,实际上并不需要使用此功能,并且可以通过其他方式实现该功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.