0

I need to send an extra parameter while I am trying to delete one or more rows in jQgrid. I have found the following:

But those are one/two year old answers and I think jQgrid has changed since then. I am using the formDeleting option from jQgrid defined as follow:

formDeleting: {
    url: '/ajax/forms/delete',
    delicon: [true, "left", "fa-scissors"],
    cancelicon: [true, "left", "fa-times"],
    width: 320,
    caption: 'Delete form',
    msg: 'Are you sure you want to delete this form?',
    beforeShowForm: function ($form) {
        var rowids = $form.find("#DelData>td").data("rowids");

        if (rowids.length > 1) {
            $form.find("td.delmsg").html('Are you sure you want to delete all the selected forms?');
        }
    },
    afterComplete: function (response, postdata, formid) {
        if (response.responseText === "true") {
            alert("The form was deleted successfully.", "Information");
        } else {
            alert("Something went wrong, the form could not be deleted.", "Error");
        }
    }
}

How do I add an extra parameter to the request so I can get it on the backend?

ReynierPM
  • 17,594
  • 53
  • 193
  • 363

1 Answers1

0

I'd recommend you to use onclickSubmit callback close to the answer, but to place the code of the onclickSubmit callback inside of formDeleting. The usage of serializeDelData inside of formDeleting inside of formDeleting is possible too, but it's better to use it in case of more deep changing in the posted data, like the usage of JSON.stringify, for example.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • 1
    @ReynierPM: Look at https://jsfiddle.net/OlegKi/aw47ytqz/2/ where I added `localReader: { id: "Id" }`, modified the code of `isDisplayButtons` and added the call of `navButtonAdd` at the end of the code. – Oleg Jan 16 '18 at 18:10
  • `localReader` is because the data is set to by `local` or it's needed if the data is remote as well? This is part of a big grid (see [here](https://stackoverflow.com/questions/48271049/how-to-avoid-jqgrid-initial-ajax-request/48275088#48275088) I just split out my doubts in smaller questions :) – ReynierPM Jan 16 '18 at 18:13
  • 1
    @ReynierPM: `localReader: { id: "Id" }` is needed if you fills the data via local `data`, but it could be that in some cases of `loadonce: true` scenario it could be helpful too. In any way your previous demo doesn't used `Id` of the source data. – Oleg Jan 16 '18 at 18:16
  • I am having another issue: as soon as I click on the row and because of `inlineEditing` the row gets selected as well as the checkbox for such row, how do I avoid to edit the row when check|uncheck the select? – ReynierPM Jan 16 '18 at 18:20
  • @ReynierPM: I'm not sure that I understand what you *want* to implement. `onSelectRow` starts inline editing depend on the column which is clicked (not on click on `act` column). One can use `beforeSelectRow` to prevent selection on some clicks. On the other side there are many other options, which can change the behavior of selection in general. See https://github.com/free-jqgrid/jqGrid/blob/v4.15.2/ts/free-jqgrid.d.ts#L1152-L1170 – Oleg Jan 16 '18 at 18:28
  • Try this [here](https://jsfiddle.net/OlegKi/aw47ytqz/2/) click on any column `inlineEditing` will happen and the checkbox at the first column gets checked. Try to uncheck the checkbox to stop the `inlineEditing` you can't. You have to click on the `Cancel` button no matter what. I want to avoid this behavior. As soon as you try to uncheck the checkbox `inlineEditing` should stop – ReynierPM Jan 16 '18 at 18:34
  • @ReynierPM: What you want to prevent: selection or inline editing? – Oleg Jan 16 '18 at 18:35
  • And even if you click on the `Cancel` button the checkbox still checked and the line still marked – ReynierPM Jan 16 '18 at 18:35
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/163272/discussion-between-reynierpm-and-oleg). – ReynierPM Jan 16 '18 at 18:35