views:

379

answers:

2

Is it possible to tell jqGrid to send all search options in JSON format ? Hence I won't have to reformat it on the backend side.

+1  A: 

There is no direct function like that mentioned in the documentation, so you will probably have realize that manually in the beforeSubmit method of the jqGrid. I would spontaneously use jQuerys serializeArray method for the form and a JSON Serializer. Then you will have to submit the serialized Form via Ajax. Just make sure, that you return success : false, so that jqGrid doesn't submit the form.

beforeSubmit : function(postdata, formid) {
    var formarray = $('#' + formid).serializeArray();
    var httpbody = JSON.stringify(formarray);
    // Send accordingly via AJAX
    $.ajax(...);
    // This looks kind of weird, but we don't want jqgrid to continue cause it was sent already
    return { success : false, message : "Successffully saved" };
}

Doesn't seem like the nicest sollution though but the beforeSubmit Event is probably the only place to dig into it.

Daff
+1  A: 

Hi All.

I don't know how helpful this will be, but I found that I can return true here as long as I set my editurl to '#' ....

beforeSubmit : function(postdata, formid) {

                    if (isValid) {
                        $.ajax({
                            type: "POST",
                            async: false,
                            contentType: "application/json; charset=utf-8",
                            url: "/RateIQ/Main.aspx/Accessorial/AccessorialDetailSave",
                            data: JSON.stringify(postdata),
                            dataType: "json"
                        });
                    }
                    return [isValid, ""]; 

} and I've experienced no side effects so far...

Robert Wafle