jqGrid Delete a Row(jqGrid 删除一行)
问题描述
我已经创建了我的网格,并希望使用网格的默认行为来删除一行.
I have created my grid and would like to use default behaviour of the grid to delete a row.
这是我的网格设置代码:
This is my grid setup code:
$("#grid").jqGrid('navGrid', '#grid_pager',
{ add: true, addtitle: 'Add Customer',
edit: true, edittitle: 'Edit Customer',
del: true, deltitle: 'Delete Customer',
refresh: true, refreshtitle: 'Refresh data',
search: true, searchtitle: 'Advanced search filters',
addfunc: addReferent, editfunc: editReferent
},
{}, // default settings for edit
{}, // default settings for add
{ // define settings for Delete
mtype: "post",
reloadAfterSubmit: true,
url: wsBaseUrl + 'CustomerService.asmx/DeleteCustomer',
resize: false,
serializeDelData: function(postdata) {
return JSON.stringify({ customerID: postdata.id });
}
},
{ // define settings for search
closeOnEscape: true, multipleSearch: true, closeAfterSearch: true
},
{}
);
这是在服务器上定义的网络服务方法
and this is the web service method defined on the server
[WebMethod]
public OperationResult Deletecustomer(string customerID)
{
}
但不幸的是,当我单击删除按钮并在确认窗口上单击确定时,我收到一条错误消息 404.如下图所示
but unfortunately when I click the delete button and click ok on the confirm window I get an error saying 404. as in the following picture
我做错了什么?
我已将以下代码添加到我的 jqGrid 初始化中
I have added the following code to my jqGrid Initialization
// Set defaults value for jqGrid
$.jgrid.defaults = $.extend($.jgrid.defaults, {
mtype: 'post',
datatype: 'json',
jsonReader: {
root: "d.Rows",
page: "d.Page",
total: "d.Total",
records: "d.Records",
repeatitems: false,
userdata: "d.UserData",
id: "Id"
},
ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
serializeGridData: function (postData) {
return JSON.stringify(postData);
},
ajaxDelOptions: { contentType: 'application/json; charset=utf-8' },
serializeDelData: function (postData) {
return JSON.stringify(postData);
},
loadui: "block",
multiboxonly: true,
rowNum: 25,
rowList: [25, 50, 100],
altRows: true,
altclass: 'ui-priority-secondary',
autoencode: true,
autowidth: true,
rownumbers: true,
rownumWidth: 30,
gridview: true,
hoverrows: true,
viewrecords: true
});
但我仍然遇到同样的错误...
but I still get the same error...
推荐答案
也许你应该只使用 JSON.stringify
(来自 json2.js) 在 serializeDelData
内.您没有发布您需要删除的网络方法 DeleteCustomer
的原型,但您的问题可能可以通过以下代码解决:
Probably you should just use JSON.stringify
(from json2.js) inside of serializeDelData
. You don't posted the prototype of your web method DeleteCustomer
which you need to delete, but probably your problem could be fixed with the following code:
serializeDelData: function(postdata) {
return JSON.stringify({customerID: postdata.id});
}
使用 ASMX 服务时的另一个常见问题.可能需要定义调用的 Web 方法的所有参数(参见 这里一个例子).
One more common problem in case of the usage of ASMX services. It can be need to define all parameters of the web method called (see here an example).
ajaxDelOptions: { contentType: "application/json" }
参数的用法也大多是必需的.
The usage of ajaxDelOptions: { contentType: "application/json" }
parameter is also required mostly.
使用 Fiddler 或 Firebug 来捕获和分析 HTTP 流量.
It can be helpful to use Fiddler or Firebug to capture and analyse the HTTP traffic.
这篇关于jqGrid 删除一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:jqGrid 删除一行
基础教程推荐
- 如何激活MC67中的红灯 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- SSE 浮点算术是否可重现? 2022-01-01