Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
794 views
in Technique[技术] by (71.8m points)

asp.net mvc - Custom Delete Function in 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
);

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

alt text

Where am I wrong?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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
    // ...
);

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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...