在 jqgrid 中实现删除和编辑操作

2022-01-18 00:00:00 grid web-services jquery javascript jqgrid

我有以下 JQgrid 实现

i have the following JQgrid implementation

    colModel: [
                { name: 'NameEn', index: 'NameEn', width: 100, align: 'left' },
                { name: 'Desc', index: 'Desc', width: 100, align: 'left' },
                { name: 'ID', index: 'ID', width: 100, align: 'left', hidden:true }
],
    caption: "Management",
    gridview: true,
    rownumbers: true,
    rownumWidth: 40,
    scroll: 0,
    rowNum: 100,
    sortname: 'ID',
    pager: '#pager',
    sortorder: "asc",
    viewrecords: true,
    autowidth: true,
    width: '100%',
    height: '100%',
    jsonReader: { root: "GridData", page: "CurrentPage", total: "TotalPages", records: "TotalRecords", repeatitems: false, id: "00" }

};

SectorGrid.prototype.SetupGrid = function (selector) {
    jQuery(selector).html('<table id="grid"></table><div id="pager"></div>');
    var grid = jQuery("#grid").jqGrid(this.gridConfiguration);

    jQuery("#grid").navGrid('#pager',{edit:false,add:false,del:true,search:false})
};

我想添加删除功能,删除调用带有 url http://localhost/的 web 服务services.svc/sector(id) 和服务只是获取 id 并且它会自己处理所有事情我也想使用不同的 url http://localhost/services.svc/sector 并接收具有上述相同信息的 json 对象.我真的尝试配置它,但它不会工作有人可以帮我在此,如果您在 jqgrid 或自定义按钮中使用了删除选项,但我不想使用 editurl 属性,这并不重要.

i want to add a delete functionality, the delete call a webservice with the url http://localhost/services.svc/sector(id) and the service just take the id and it will handle everything by it self also i would like to edit data using differnt url http://localhost/services.svc/sector and this receives json object with the same information above. i really tried to configure it but it wont work can somebody help me in this, it dosent matter if u used the delete option in the jqgrid or custom buttons but i dont want to use the editurl property.

请举一个完整的例子如何实现这个继续我上面的代码

please put a full example how to implement this continue to my code above

更新:休息方法

[WebInvoke(UriTemplate = "Sector({iD})/", Method = "DELETE",  ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
        [OperationContract]
        bool DeleteSector(string iD)

提前致谢

推荐答案

尝试在表单中使用navGrid

jQuery("#grid").jqGrid('navGrid', '#pager',
    {edit: false, add: false, search: false}, {}, {},
    { // Delete parameters
        ajaxDelOptions: { contentType: "application/json" },
        mtype: "DELETE",
        serializeDelData: function () {
            return ""; // don't send and body for the HTTP DELETE
        },
        onclickSubmit: function (params, postdata) {
            params.url = '/Sector(' + encodeURIComponent(postdata) + ')/';
        }
    });

相关文章