0
  • using jqGrid's ASP.NET MVC component

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:

  • add the parameter to the set of data that jqGrid will send along when an Add (or edit, for that matter) request is sent (right now it just sends the Shoe information) - the problem with this is that I'd have to programatically add the parameter to the jqGrid after it's instantiated, and so far I have not been able to do that, with either editParams or addParams.

  • hook into an event right before the request goes out and add the additional information in then. The problem here is I haven't been able to find an event that reliably fires right before the "add a new row" request is sent.

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

4

1 回答 1

1

您可以监听beforeSubmitaddOptions/editOptions.. 的事件以向请求添加额外的参数。

前任。

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);
于 2012-07-06T03:18:33.393 回答