内联保存按钮的jqgrid onClickSubmit和afterSubmit事件

时间:2013-02-08 17:16:23

标签: json events jqgrid inline-editing

我一直在寻找一段时间的答案,找不到足以回答我问题的答案......

我有一个JQ网格,它使用内联和表单编辑,并使用blockUI显示“工作”消息,而服务器正在做它的东西。 这对于表单编辑/添加/删除非常有效,因为我使用 onclickSubmit blockUI afterSubmit unblockUI

问题出现了,因为我无法在内联编辑中找到解决方法。任何人都可以建议一种方法来实现这一目标吗?

我想要的是知道在点击“保存”图标时(在请求发送到服务器之前)触发事件的位置,所以我可以阻止UI:

以及捕获从服务器发回响应时触发的事件的位置。

必须有一种方法可以使用'editRow'或'saveRow'执行此操作,如下所示,但我无法确定放置命令的位置和事件。


在Olegs响应后编辑

我将把调用放在'editRow'函数中? 如果我使用onSelectRow,它会在选择行时对其进行操作 - 这会更改网格的行为 - 因为它现在不显示“操作”列中的“保存”按钮。 我可以在哪里进行'editRow'调用,以便在选择inLine编辑图标时触发它?

    $(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
        });
    });

1 个答案:

答案 0 :(得分:2)

例如,您可以使用jqGrid的serializeRowData回调,或者在将请求发送到服务器之前使用ajaxRowOptions.beforeSend来调用blockUI / block。例如,您可以添加到jqGrid选项列表

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

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

您必须同时在unblockUI(或unblock)和aftersavefunc中致电successfunc / errorfunc