javascript jQuery jqGrid 在编辑行完成时显示消息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6791463/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 21:53:47  来源:igfitidea点击:

jQuery jqGrid Show message when an edit row is complete

javascriptjqueryjqgriddata-manipulation

提问by michele

I am following this tutorial here http://www.trirand.com/blog/jqgrid/jqgrid.htmlin LiveDataManipulation->EditRow

我在这里关注本教程http://www.trirand.com/blog/jqgrid/jqgrid.html在 LiveDataManipulation->EditRow

My grid receive data from script a.php. After the user can modify this data by the jqGrid. jqGrid after the modification data will send data to script B.phpthat update my database and return a message of response like "all goes well".
I want that this response is alerted or showed to user somewhere on the page.
Reading the tutorial and here http://www.trirand.com/jqgridwiki/doku.php?id=wiki:form_editingI think that I've to use afterSubmitoption, but I haven't understood how print on the edit panel the result.

我的网格从脚本接收数据a.php。之后用户可以通过jqGrid修改这个数据。修改数据后的 jqGrid 会将数据发送到B.php更新我的数据库的脚本,并返回“一切顺利”之类的响应消息。
我希望此响应在页面上的某处被提醒或显示给用户。
阅读教程和这里http://www.trirand.com/jqgridwiki/doku.php?id=wiki:form_editing我认为我必须使用afterSubmit选项,但我不明白如何在编辑面板上打印结果.

I have written:

我已经写了:

$("#editImpresa").click(function(){
var gr = jQuery("#tabImprese").jqGrid('getGridParam','selrow');
if( gr != null ) jQuery("#tabImprese").jqGrid('editGridRow',gr,{
    height:690,
    width:500,
    closeAfterEdit : true,
    reloadAfterSubmit:false,
    afterSubmit: function(response,postdata){ 
       if(response.responseText=="ok")
            success=true;
        else success = false;

        return [success,response.responseText] 
    }
});

How can I do it? Thanks.

我该怎么做?谢谢。

回答by Oleg

First of all the option closeAfterEdit:truefollows to closing of the edit form after the successful server response. You should change the setting to the default value closeAfterEdit:falseto be able to show anything.

首先是在closeAfterEdit:true服务器成功响应后关闭编辑表单的选项。您应该将设置更改为默认值closeAfterEdit:false,以便能够显示任何内容。

Next I would recommend you to use navigatortoolbar instead of creating a button after outside of the grid. In the case you can use

接下来,我建议您使用导航器工具栏,而不是在网格之外创建按钮。在这种情况下,您可以使用

var grid = jQuery("#tabImprese");
grid.jqGrid('navGrid','#pager', {add:false,del:false,search:false}, prmEdit);

One more good option is to use ondblClickRowevent handler

一个更好的选择是使用ondblClickRow事件处理程序

ondblClickRow: function(rowid) {
    $(this).jqGrid('editGridRow',rowid,prmEdit);
}

(see here) or both ways at the same time.

(参见此处)或同时使用两种方式。

In any way you have to define the options of editGridRowmethod (the prmEdit). It's important to know that afterSubmitwill be called only if the server response not contains error HTTP status code. So you should use errorTextFormatto decode the error server response. The afterSubmitevent handler you can use to display status message.

无论如何,您都必须定义editGridRow方法(prmEdit)的选项。重要的是要知道只有在服务器响应不包含错误 HTTP 状态代码时才会调用afterSubmit。所以你应该使用errorTextFormat来解码错误服务器响应。可用于显示状态消息的afterSubmit事件处理程序。

In the demo I used only errorTextFormatto demonstrate both displaying of the status and error message:

在演示中,我仅errorTextFormat用于演示状态和错误消息的显示:

enter image description here

在此处输入图片说明

The status message goes away in 3 seconds:

状态消息在 3 秒后消失:

enter image description here

在此处输入图片说明

The corresponding demo you will find here.

您将在此处找到相应的演示。

In real example you will of cause place the code writing status message inside of afterSubmitevent handler and the code which returns the error message inside of errorTextFormat.

在实际示例中,您将导致将编写状态消息的代码放置在afterSubmit事件处理程序中,并将返回错误消息的代码放置在errorTextFormat 中