【问题标题】:on editing a row using editGridRow function of Jqgrid, it not only edits data but also changes uneditable id column value to selrowid在使用 Jqgrid 的 editGridRow 函数编辑一行时,它不仅可以编辑数据,还可以将不可编辑的 id 列值更改为 selrowid
【发布时间】:2013-11-27 16:10:46
【问题描述】:

我正在创建一个 jqgrid,它由来自 jsp 的数据填充。它有 3 列名称、描述和不可编辑的列 ID。我有 5 个按钮:页面上的新建、修改、删除、确定和取消。我想让用户通过弹出表单在本地编辑/添加数据到 jqgrid,然后单击保存将其添加到数据库。

$("#template-list").jqGrid
  ({ 
        url:'getTemplateCategories.jsp?TrUserId=122',
        datatype: 'xml', 
        mtype: 'post',
        colNames:['Name','Description','id','SaveAs'],
        colModel :[
                    {name:'Name',index:'Name', width:300, align:'left', sortable:false,xmlmap:"catName", editable:true},
                    {name:'Description',index:'Description', width:300, align:'left', sortable:false,xmlmap:"catDescription", editable:true},
                    {name:'id',index:'id', width:0, align:'left', sortable:false,xmlmap:"catId" , hidden: false},
                    {name:'SaveAs', index:'SaveAs', width:0, align:'left', sortable:false, hidden: false}
                   ],
        xmlReader: { 
                     root:"Categories", 
                     row:"item",                  
                     repeatitems:false                
                   },
        height : '461',
        scrollOffset:"0",
        hidegrid: "No",
        closeAfterAdd : true,   
        closeAfterEdit : true,    
        border: '2',
        pager: '#template-pager',
        viewrecords: true,
        minheight: '190',
        width: '600',
        autoheight: true,
        mtype:'POST',
        forceFit : true,    
        align:'left',   
        emptyrecords: "Nothing to display",
        rowNum:'20',
        paging: true,
        editurl: 'TemplateCategoryWebView.jsp',
        cellsubmit:'clientArray',               
        loadonce : true  
   });    

我正在使用以下代码在行选择后单击按钮添加/编辑一行:

 function add()
{   
    $("#template-list").jqGrid('editGridRow',"new",{width:400,height:200,reloadAfterSubmit:false,closeAfterAdd:true});
}
function modify()
{   
    var selRowId = $('#template-list').jqGrid('getGridParam','selrow');
    var rowid =  $('#template-list').jqGrid('getCell', selRowId, 'id') ;
    var rowData = $("#template-list").jqGrid('getRowData',rowid);
    if( selRowId)
    {
        $('#template-list').jqGrid('editGridRow',selRowId,{width:400,height:200,reloadAfterSubmit:false,closeAfterEdit:true});
        alert("selRowId  :  "+selRowId+"    rowid : "+rowid);
        EditCats=EditCats.concat(rowid) ;   

    }   
    else
    {
        alert("Please select a row");
    }
}

现在,当我编辑特定行时,它会打开该记录并允许用户编辑名称和描述值,当我单击提交按钮时,它不仅会在 jqgrid 本地保存编辑的值,还会更改“id”列值为“selRowId”的值。有人可以解释发生了什么,因为我正在努力解决这个问题。我希望此功能的行为与我提到的完全一样,而不是通过任何其他替代方法(如内联编辑),因为这是一个迁移项目,他们希望保留该功能之前的工作方式(即使用弹出屏幕)以减少客户学习曲线。很长一段时间以来,我一直在寻找解决此问题的方法,但一直没有找到。

它还尝试在 editGridRow 中传递 id 值,但它没有用。请帮忙。

谢谢, 安妮塔

【问题讨论】:

  • 您能否将colModel (name:'id',index:'id') 中的id 更改为其他名称并重复相同的测试?例如,您可以使用name:'catId' 代替name:'id',index:'id'。问题是名称id 将在编辑数据期间在内部使用。
  • @Oleg 感谢您的回复。更改了 colModel 值,现在它可以正常进行编辑,但现在添加新行时,id 应该是 jqg1 时是空白的。
  • 您至少应该使用 reloadAfterSubmit: true 选项添加表单。如果您不使用它,则必须在editurl: 'TemplateCategoryWebView.jsp' 的服务器响应中返回id (catId) 的新值。如果响应将是不包含在 XML 中,那么 jaGrid 将为您修改 rowid。如果您想向用户显示 id(在 catId 列中)或者服务器响应不是新的 id(例如 XML 包装),那么您必须使用表单编辑的 afterSubmit 回调。所以我的建议是:使用reloadAfterSubmit: true 添加至少用于乞讨。
  • @oleg 很抱歉回复晚了,但也没有用
  • @Anita,我能就这个问题问你一些问题吗...如果这个问题解决了吗??

标签: jquery jqgrid save edit


【解决方案1】:
  $("#template-list").jqGrid
  ({ 
        url:"getTemplateCategories.jsp?TrUserId=<%=TrUserId%>",
        datatype: 'xml', 
        mtype: 'post',
        colNames:['Name','Description','Id'],
        colModel :[
                    {name:'Name',index:'Name', width:$(window).width()/2, align:'left', sortable:false,xmlmap:"catName", editable:true},
                    {name:'Description',index:'Description',  width:$(window).width()/2, align:'left', sortable:false,xmlmap:"catDescription", editable:true},
                    {name:'Ids',index:'Ids', width:0, align:'left', sortable:false,xmlmap:"catId" , hidden: true},
                    ],
        xmlReader: { 
                     root:"Categories", 
                     row:"item",                  
                     repeatitems:false                
                   },
        height: $(window).height()-110,        
        width: $(window).width() - 11,
        autowidth: false,
        autoheight: false,
        shrinkToFit: true,
        scrollOffset:"0",
        forceFit : true,
        hidegrid: "No",
        closeAfterAdd : true,   
        closeAfterEdit : true,    
        border: '2',
        pager: '#template-pager',
        viewrecords: true,
        mtype:'POST',           
        align:'left',               
        rownumbers : true,
        emptyrecords: "Nothing to display",
        rowNum:'20',
        paging: true,
        editurl: 'TemplateCategoryWebView.jsp',
        cellsubmit:'clientArray',
        loadonce : true

   });  

【讨论】:

    猜你喜欢
    • 2011-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-25
    相关资源
    最近更新 更多