【问题标题】:Message afterAdd in new dialog jqGrid (navGrid)在新对话框 jqGrid (navGrid) 中添加后的消息
【发布时间】:2012-12-04 09:17:50
【问题描述】:

您好,我在添加操作中有这个 navGrid 定义。

Grid.id >> $("#<%=Me.Id & "_" %>lstPreciosSUD")

{ width: 350, resize: false, closeAfterAdd: false, recreateForm: true,
    clearAfterAdd:false, viewPagerButtons: true, afterComplete: estadoReplicado,
    ,afterSubmit: function(response) { 
                if (response.responseText == "OK") {

                    alert("we are inside");

                    var myInfo = '<div class="ui-state-highlight ui-corner-all">' +
                        '<span class="ui-icon ui-icon-info" ' +
                        'style="float: left; margin-right: .3em;"></span>' +
                        '<span>Registro insertado correctamente!</span></div>',
                    $infoTr,
                    $infoTd;
                    $infoTr = $("#TblGrid" + "<%=Me.Id & "_" %>lstPreciosSUD" + ">tbody>tr.tinfo");
                    $infoTd = $infoTr.children("td.topinfo");
                    $infoTd.html(myInfo);
                    $infoTr.show();

                    setTimeout(function () {
                        $infoTd.children("div")
                            .fadeOut("slow", function () {
                                  $infoTr.hide();
                            });
                    }, 6000);

                        //alert("Registro creado.");
                        return [true,''];
                } 
                else { 
                        return [false, "Error creando precio de suplemento!"];
                } 
            },
    beforeSubmit: function(postdata){ 
        if ((postdata.tpb_importe == "") || (postdata.fini == "") || (postdata.ffin=="")) {
            return[false,"Importe y fechas es obligatorio!"]; 
        } else { return [true,""] }
    }
}}

在第二个或日期的输入中,如果为空,则此返回 (return [false,"Importe y fechas es obligatorio!"] ") 在对话框中从 beforeSubmit 向我返回一条红色消息,例如 http://i.imgbox.com/ackwIZvQ.jpg

在这种情况下,我必须使用closeAfterAdd:falseclearAfterAdd:false,但我想知道并且我认为使用afterSubmit 来显示绿色(例如)消息,如果一切正常,只需一点功能即可这个,但是如果我使用上面的afterSubmit 函数,并且它可以,不显示任何消息,如错误消息,是否可以显示任何 OK 消息?如果有错误,它会以红色显示我在后台看不到它是如何添加新记录的,但在对话框中不显示任何消息。

谢谢。

【问题讨论】:

    标签: jquery jqgrid return message


    【解决方案1】:

    如果我理解你是正确的,你会在the answer(见the demo)中找到这种实现的例子。它显示了如何以与添加标准错误消息相同的方式使用添加自定义文本。在演示中,我仅使用errorTextFormat模拟 加载。您应该将显示成功消息的代码移动到afterSubmit

    更新afterSubmit 的代码可能看起来像(我没有测试代码)

    afterSubmit: function (jqXHR) {
        var myInfo = '<div class="ui-state-highlight ui-corner-all">' +
                '<span class="ui-icon ui-icon-info" ' +
                'style="float: left; margin-right: .3em;"></span>' +
                '<span>The row is successfully added</span></div>',
            $infoTr,
            $infoTd;
    
        if (jqXHR.responseText !== "OK") {
            return [false, jqXHR.responseText];
        }
    
        $infoTr = $("#TblGrid_" + $.jgrid.jqID(this.id) + ">tbody>tr.tinfo"),
        $infoTd = $infoTr.children("td.topinfo");
        $infoTd.html(myInfo);
        $infoTr.show();
    
        // hide the info after 3 sec timeout
        setTimeout(function () {
            $infoTd.children("div")
                .fadeOut("slow", function () {
                    // Animation complete.
                      $infoTr.hide();
                });
        }, 3000);
    }
    

    【讨论】:

    • 嗨奥列格!我在答案中看不到您的 errorTextFormat 代码。你能帮助我吗?我已经在所有答案链接页面中进行了搜索!再次感谢!
    • @bombai:可以打开the demo的源代码。如果您有一些问题,我可以在我的答案中添加部分代码。
    • 嗨奥列格!我可以看到代码,但我不知道应该在哪里以及如何使用!我必须直接放在aftersubmit上并在寻呼机中调用它还是没有必要?再次感谢。
    • 嗨,OLeg!如果我将此代码放入添加或编辑操作而不返回 true 可以保存新数据,如果我放入 return [true,''] 保存数据但不显示任何消息!你有什么想法吗?我已经用我的代码编辑了第一篇文章!谢谢
    • @bombai:不客气!图标的颜色将来自您使用的 jQuery UI CSS。因此,您可以针对ThemeRoller 自定义主题。或者,您可以混合从 另一个 著名的 CSS 中获取图标,例如包含绿色图标的 le-frog。如果您遇到实施问题,您可以提出新问题,我会尽力帮助您。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-23
    • 2011-04-13
    • 1970-01-01
    • 2011-11-24
    相关资源
    最近更新 更多