jqgrid onClickSubmit and afterSubmit events of inline Save button

Andrew Humphries picture Andrew Humphries · Feb 8, 2013 · Viewed 9k times · Source

I've been looking around for an answer for a little while now and cannot find an one that sufficiently answers my question...

I have a JQ Grid that utilises both inline and form editing and uses blockUI to show a 'working' message while the server is doing it's stuff. this works marvellously for form editing/adding/deleting, as I use the onclickSubmit to blockUI and afterSubmit to unblockUI.

The problem comes as I cannot find a way to do this in Inline Edit. Can Anyone Suggest a way to achieve this?

What i want is to know where to catch the event that is fired when the 'Save' icon is clicked (before the request is sent to the server) so I can blockUI:

and where to catch the event that is fired when the response is sent back from the server.

There must be a way to do this using The 'editRow' or 'saveRow' as below, but i cannot work out where and in what events to Put commands such as these.


EDIT after Olegs Response

Where would I put the call to the 'editRow' function? If I use onSelectRow, It actions the it upon selecting the row - this changes The behaviour of the grid - as it now does not show the 'save' button in The Action column. Where Can I put the 'editRow' call so that it is fired when The inLine edit icon is selected?

    $(document).ready(function() {
        $('#jpgCustomers').jqGrid({
            //url from wich data should be requested
            url: '@Url.Action("Customers")',
            //type of data
            datatype: 'json',
            //url access method type
            mtype: 'POST',
            serializeRowData: function(postData) {
                $.blockUI({message: ("#working")});
                return postData;
            },
            //columns model
            //columns names
            colNames: ['No.', 'Name', 'FullName', 'Description', 'Enabled', 'Email Address', 'Phone', 'Pager', 'Fax', 'Comments', ' '],
            colModel: [
                //displayed Columns
                { name: 'Number', index: 'Number', align: 'center', width: 40, editable: false, search: false },
                { name: 'LogonName', index: 'LogonName', align: 'left', width: 80, editable: true, search: true, stype: 'text', editrules: { required: true } },
                { name: 'FullName', index: 'FullName', align: 'left', width: 200, editable: true, search: true, stype: 'text', editrules: { required: true } },
                { name: 'Description', index: 'Description', align: 'left', width: 300, editable: true, search: true, stype: 'text' },
                { name: 'Enabled', index: 'Enabled', align: 'center', width: 80, editable: true, formatter: SFTPEnabledFormatter, unformat: SFTPEnabledUnformatter, edittype: 'select', editoptions: { value: '-2:Inherited;0:Disabled;1:Enabled' }, search: true, stype: 'select', searchoptions: { value: "-1:All;-2:Inherited;1:Enabled;0:Disabled" } },
                //Hidden Columns
                { width: 60, name: 'Email', index: 'Email', hidden: true, editable: true, editrules: { required: true, edithidden: true }, editype: 'email' },
                { width: 60, name: 'Phone', index: 'Phone', hidden: true, editable: true, editrules: { required: false, edithidden: true, number: true, minValue: 0 }, editype: 'text' },
                { width: 60, name: 'Pager', index: 'Pager', hidden: true, editable: true, editrules: { required: false, edithidden: true, number: true, minValue: 0 }, editype: 'text' },
                { width: 60, name: 'Fax', index: 'Fax', hidden: true, editable: true, editrules: { required: false, edithidden: true, number: true, minValue: 0 }, editype: 'text' },
                { width: 120, name: 'Comments', index: 'Comments', align: 'left', hidden: true, editable: true, editrules: { required: false, edithidden: true }, edittype: 'textarea', editoptions: { rows: '3', cols: '60' } },
                //Action column
                {
                    name: 'myac',
                    width: 80,
                    fixed: true,
                    sortable: false,
                    resize: false,
                    editable: false,
                    search: false,
                    formatter: 'actions',
                    formatoptions: {
                        onSuccess: function(response) {
                            debugger;
                            $.unblockUI();
                                var jsonResponse = $.parseJSON(response.responseText);
                                if (jsonResponse.State != 'Success') {
                                    return [false, jsonResponse.ResponseMessage];
                                } else {
                                    return [true];
                                }                            },
                        onError :function(rowid, response, textStatus) {
                            debugger;
                            $.unblockUI();
                        },
                        keys: true,
                        delOptions: {
                            url: encodeURI('@Url.Action("DeleteCustomer")'),
                            onclickSubmit: function(params, posdata) {
                                $.blockUI({message: ("#working")});
                            },
                            afterSubmit: function(response, postData) {
                                $.unblockUI();
                                var jsonResponse = $.parseJSON(response.responseText);
                                if (jsonResponse.State != 'Success') {
                                    return [false, jsonResponse.ResponseMessage];
                                } else {
                                    return [true];
                                }
                            },
                            beforeShowForm: function(form) {
                                var dlgDiv = $("#delmod" + jpgCustomers.id);
                                CenterDialog(dlgDiv);
                                var sel_id = $("#DelData>td:nth-child(1)").text();
                                $("td.delmsg", form).html("Delete User <b>" + $("#jpgCustomers").jqGrid('getCell', sel_id, 'LogonName') + "</b>?");
                            }
                        }
                    }
                }
            ],
            reloadAfterSubmit: true, 
            //pager for grid
            pager: $('#jpgpCustomers'),
            //number of rows per page
            rowNum: @(Model.RowsInCustomerGrid),
            //initial sorting column
            sortname: 'FullName',
            //initial sorting direction
            sortorder: 'asc',
            //we want to display total records count
            viewrecords: true,
            //grid height
            height: '100%',
            //where to go on submit of edit/add
            editurl: encodeURI('@Url.Action("EditCustomer")'),
            //subgrid
        });
    });

Answer

Oleg picture Oleg · Feb 8, 2013

You can use serializeRowData callback of jqGrid for example or use ajaxRowOptions.beforeSend to call blockUI/block before the request will be sent to the server. For example you can add to the list of jqGrid options

serializeRowData: function (postdata) {
    $(this).block({message: "<h1>Saving the data...</h1>"});
    return postdata;
}

or

ajaxRowOptions: {
    beforeSend: function () {
        $("#grid").block({message: "<h1>Saving the data...</h1>"});
    }
}

You have to call unblockUI/unblock in both aftersavefunc (or successfunc) and errorfunc.