Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass additional postdata into an add record function - JQGrid - MVC . NET

I am using the JQGrid plugin on an MVC project. I am trying to avoid using 'Session'. I have been able to pass extra postdata into my edit and delete functions, using the serializedata methods from JQGrid.

E.G.

serializeEditData: function (postdata) 
{
    var rowdata = jQuery('#gridId').getRowData(postdata.id);
    return {id: postdata.id, oper: postdata.oper, SomeExtraData: $('#extradata').val()};
}

However, there doesn't appear to be a serializeAddData function. Is there another way to alter the post data for the add method before it is sent?

like image 929
Joe Avatar asked Jan 21 '23 07:01

Joe


1 Answers

There are one method editGridRow which implement form editing for both "Edit" and "Add" dialogs. So the same event han`ler serializeEditData can be used in both cases. For example,

$("#list").jqGrid('navGrid','#pager',
    {/*navGrid options*/},
    {/*edit options*/
        serializeEditData: function (postdata) {
            // your implementation of serializeEditData for edit
        }
    },
    {/*add options*/
        serializeEditData: function (postdata) {
            // your implementation of serializeEditData for add
        }
    },
    {/*del options*/},
    {/*search options*/}

/ );

Typically serializeEditData event is very practical if you need convert all the posted data in another format, for example to make JSON serialization. To be able to pass extra postdata parameters you can use editData parameter instead which has the same meaning like postData parameter of jqGrid:

$("#list").jqGrid('navGrid','#pager',
    {/*navGrid options*/},
    {/*edit options*/
     editData: {SomeExtraData: $('#extradata').val()}
    },
    {/*add options*/
     editData: {SomeExtraData: $('#extradata').val()}
    },
    {/*del options*/},
    {/*search options*/}
);

or better in this way (see this answer about the usage of functions as the property of postData):

$("#list").jqGrid('navGrid','#pager',
    {/*navGrid options*/},
    {/*edit options*/
     editData: {SomeExtraData: function() {return $('#extradata').val();}}
    },
    {/*add options*/
     editData: {SomeExtraData: function() {return $('#extradata').val();}}
    },
    {/*del options*/},
    {/*search options*/}
);
like image 96
Oleg Avatar answered Jan 29 '23 15:01

Oleg