user15486
user15486

Reputation:

How to send extra data in jqGrid's "Add Row" request?

I have a jqGrid that is working splendidly except for one thing: it's a grid of Shoes that I must associate with a ShoeOwner (object names changed to protect the innocent)

So when I have a grid, it displays only the Shoes that a particular ShoeOwner owns. And when a user of the system decides to add a Shoe, before that request is sent, I need to add an additional parameter to the request that associates this new Shoe with this particular ShoeOwner. (otherwise the request will arrive at the Controller as just a lonely Shoe.)

Since I'm using the MVC component, I can't just stick this into the jqGrid() object when it's instantiated - it seems like I either need to:

Does anyone know how I can associate an entity added with jqGrid with the parent entity with which it belongs?

Upvotes: 0

Views: 1671

Answers (1)

VJAI
VJAI

Reputation: 32758

You can listen to the beforeSubmit event of the addOptions/editOptions.. to add additional parameters to the request.

Ex.

var addOptions = {
    editCaption: 'Add Post',
    processData: "Saving...",
    width: 420,
    closeAfterEdit: true,
    closeOnEscape: true,

    beforeSubmit: function (postdata, form) {
        var $grid = $(gridName);

            // additional parameters
        postdata.AdditionalData1 = ...
        postdata.AdditionalData2 = ...

        return [true];
    }
};


$(gridName).jqGrid('navGrid', pagerName, {
            cloneToTop: true,
            search: true,
            view: true
        },

editOptions, addOptions, deleteOptions);

Upvotes: 1

Related Questions