jqgrid表单编辑:有关删除行后的操作的问题 [英] jqgrid Form editing : questions about actions after deleting a row

查看:158
本文介绍了jqgrid表单编辑:有关删除行后的操作的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经过长时间的搜索,我成功地通过表单编辑删除了jqgrid中的一行.

After long searches, I succeed to delete a row in a jqgrid with form editing.

但是,还有两件事:

  • 如何在删除行的情况下重新加载网格?
  • 如果无法删除该行,如何显示信息以及原因?

我试图在事件"afterSubmit"中搜索传递给该函数的参数,但是对于如何操作这些参数没有真正的解释.

I tried to search in the arguments passed to the function in the event "afterSubmit", but there is no real explanations about how to manipulate these arguments.

网格的创建:

tableToGrid("#TabUser", {
    caption: 'Gestion des Utilisateurs',
    width: 'auto',
    height: "auto",
    hidegrid: false,
    pager:'#DivUser',
    rowNum:10,
    cellEdit: true,
    cellsubmit: 'remote',
    cellurl: 'Adminuser',
    colModel: [{name:'Id', editable:false, width:50},
               {name:'Login', editable:false, width:150},
               {name:'Nom', editable:true, width:200},
               {name:'Prénom', editable:true, width:200},
               {name:'Rôle', editable:true, width:80, edittype:'select', 
                editoptions: { multiple: false, value:{ADMIN:'ADMIN',GUEST:'GUEST'}}},
               {name:'Email', editable:true, width:200}],
    beforeSubmitCell: function(rowid, celname, value, iRow, iCol) {
        var rowData = jQuery(this).getRowData(rowid); 
        var idUser= rowData['Id'];// On récupère l'Id du user en cours d'édition
        return {idUser:idUser}; }

});

导航:

$("#TabUser").navGrid('#DivUser',
        {edit:false,add:false,del:true,search:false},{}, {},
        {width:500, url:'Adminuser',
            reloadAfterSubmit:true,
             onclickSubmit: function(param){ 
                var sr = jQuery('#TabUser').getGridParam('selrow');
                var idUser = jQuery('#TabUser').getCell(sr,'Id');
                return {idUser:idUser}; },
            afterSubmit: function(reponse, data) {
                $("#TabUser").trigger('reloadGrid');
                $("#eData").click(); // clic sur "Annuler"
                return [true,"Supression réussie"];
            }
        });

响应"和数据"的值是什么? 如何重新加载网格?

What are the values of "response" and "data" ? How to reload the grid ?

该行已在URL中使用Adminuser(用Java编写)有效地删除了.

The row is effectively deleted in the database with the url 'Adminuser' (written in java).

推荐答案

我认为您真正的问题不是删除行后重新加载网格. tableToGrid将创建的网格具有datatype: 'local',不需要从服务器重新加载数据.

I think that your real problem is not reloading of the grid after deleting of the row. The grid which will be created by tableToGrid have datatype: 'local' and reloading of data from the server not needed.

您真正的问题是jqGrid 3.4.1中的错误已修复(请参见此处)在jqGrid的代码中.因此,已删除的行不会从网格中删除.问题是该行的代码:

Your real problem is the bug in jqGrid 3.4.1 which is fixed (see here) in the code of jqGrid. So the deleted row will be not removed from the grid. The problem is the line of code:

toarr = postdata.split(",");

错误是postdata已经是数组而不是字符串.因此,该行中的第一个获取异常,将不会执行从网格中删除该行的下一行.要解决此问题,您可以使用 github 中的最新版本的jqGrid代码,也可以修改行上方(在jquery.jqGrid.src.js中具有行号8282)到

The bug is that postdata is already array and not the string. So one get exception in the line and the next lines which delete the row from the grid will be not executed. To fix the problem you can either use the last version of the jqGrid code from the github or to modify the above line (it has line number 8282 in jquery.jqGrid.src.js) to

toarr = postdata;

或下载jquery.jqGrid.src.js的修改版本的行,并且所有代码都将正常运行:请参见

or download the modified version of jquery.jqGrid.src.js here. After that you can remove the line with $("#TabUser").trigger('reloadGrid'); from your code and all will work correctly: see the demo.

要在该行的删除"中报告来自服务器的错误信息,您只需在HTTP响应中设置错误状态代码.您还可以定义 errorTextFormat 回调,以重新格式化服务器对要显示为错误消息的HTML代码片段的响应.参见答案这一个以获取更多信息.

To report the error information from the server in the "Delete" of the row you should just set error status code in the HTTP response. You can additionally define the errorTextFormat callback which reformat the server response to the HTML code fragment which you want to display as the error message. See the answer, this one or this for additional information.

这篇关于jqgrid表单编辑:有关删除行后的操作的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆