views:

51

answers:

1

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?

+1  A: 

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.

Oleg
Thank you for helping. It works. Is there a way to get the result of the call? This way I can add some user feedback. Thanks again
Lorenzo
Ok.No problem. I have found the afterSubmit event on the docs wiki
Lorenzo
@Lorenzo: Which feedback you mean? After which call? Which "result of the call" (which call) you mean?
Oleg
@Lorenzo: I use also `afterSubmit` defined as `function (response, postdata)` and decode with `jQuery.parseJSON(response.responseText);` the information send from the server and add/modify one additional hidden column `RowVersion` which represend timestamp of the data and are used from optimistic concurency handling. Is if something what you also do?
Oleg
With result I meant the result of the ajax call to the server side delete function. With feedback I meant the feedback to be given to the user. For example: "deleted row" or "the row cannot be deleted because...". I have found how to do it using the afterSubmit event. Thanks
Lorenzo
@Lorenzo: OK! I wrote the question before I could read your previous comment. To be exactly I use `afterSubmit` only in case of successful deleting. In case of error my server part return some HTTP error code instead of "200 OK" and I use `errorTextFormat` to decode the error message send from the server. The advantage is that I con also decode exceptions in the server which my code not throws explicitly.
Oleg
In my case I use always afterSubmit. In case of error my server side code returns a different formatted response with a custom http header that I check inside the afterSubmit handler.
Lorenzo
@Lorenzo: It's pure design question. You should decide what is better for your poupose. Nevertheless I would recommend you to test which error messages will display your program in case of exceptions in your server code. For example you can simulate an error in the database access, in the type coverstion or some other error which produce an exception. Do you catch all exceptions in your server code? How look like the error message which see the user? What send server in the case (you can see that in Fiddler or Firebub). In my MVC application I do have to implement `errorTextFormat` handle.
Oleg