jqGrid中的自定义删除功能 [英] Custom Delete Function in jqGrid
问题描述
我正在尝试自定义 jqGrid 中的删除功能.
I am trying to customize the delete function in 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
);
然后我添加了(感谢此post)以下代码
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
我哪里错了?
推荐答案
如果我理解你是正确的,你想修改用于删除行的 url
以便行的 id 将是url
的一部分.你可以更轻松地做到这一点:
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
. 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
// ...
);
关于onclickSubmit
我们可以修改url
和定义serializeDelData
我们可以清除POST"消息的正文.我个人主要在服务器端使用 RESTfull 服务并使用 mtype: "DELETE"
.在这种情况下确实需要清除尸体.
With respect of onclickSubmit
we can modify the url
and defining of serializeDelData
we can clear the body of the "POST" message. I peronally mostly use RESTfull services on the server side and use mtype: "DELETE"
. In the case to clear of the body is really needed.
另一种选择是使用 delfunc
,就像您已经使用 editfunc
和 addfunc
一样.在大多数情况下,这种功能的使用并不是真正需要的,可以通过其他方式实现.
One more option is to use delfunc
like you already use editfunc
and addfunc
. In the most cases the usage of such function is not really needed and one can implement the same in other way.
这篇关于jqGrid中的自定义删除功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!