jqGrid的删除行 [英] jqGrid Delete a Row

查看:1320
本文介绍了jqGrid的删除行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了我的网格,想用网格的默认行为,删除行。

I have created my grid and would like to use default behaviour of the grid to delete a row.

这是我的网格设置code:

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 
    }, 
    {}
);

和这是在服务器上定义的web服务方法

and this is the web service method defined on the server

[WebMethod]
public OperationResult Deletecustomer(string customerID)
{
}

但不幸的是,当我点击删除按钮,然后点击OK确认窗口上我得到一个错误说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

我在做什么错了?

编辑:

我添加了以下code到我的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 。你不贴,你需要删除Web方法 DeleteCustomer 的原型,但可能你的问题可能是固定的有以下code:

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方法的所有参数(请参阅here一个例子)。

ajaxDelOptions的用法:{的contentType:应用/ JSON} 参数还需要大多

它可以帮助使用提琴手或的萤火来捕获和分析HTTP流量。

It can be helpful to use Fiddler or Firebug to capture and analyse the HTTP traffic.

这篇关于jqGrid的删除行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆