Implementing Delete and Edit operations in jqgrid

2020-02-15 07:32发布

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

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

UPDATED: Rest Method

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

thanks in advance

1条回答
你好瞎i
2楼-- · 2020-02-15 08:18

Try to use navGrid in the form

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) + ')/';
        }
    });
查看更多
登录 后发表回答