jQgrid在表单视图中显示隐藏列

时间:2011-01-10 10:30:06

标签: jquery jqgrid jqgrid-asp.net

jQuery("#CustomerDetailsGrid").jqGrid({
    //ignore other properties
    colModel: [
    { name: 'AccountNumber', index: 'AccountNumber', hidden: true, viewable: true }
],
    viewrecords: true        
});

我需要在网格视图中隐藏“帐号”列,但在表单视图中显示它。(不编辑表单

4 个答案:

答案 0 :(得分:13)

最好的方法是只添加editrules:{edithidden:true}选项。

colModel: [{ name: 'AccountNumber', index: 'AccountNumber', hidden: true, viewable: true,editrules:{edithidden:true} }]

答案 1 :(得分:11)

如果将创建“视图”对话框,则将填充有关放置在行中的每个列的信息。行的id(<tr>元素的id)将从前缀“trv_”和相应列的名称构造。重要的是要理解,在表单中将填充有关所有包含隐藏列的信息,但隐藏列的<tr>元素将是hidden(has style =“display:none;”)。因此,为了使信息可见,只需为相应的jQuery.show()元素调用<tr>函数即可。

我准备了the small demo来证明这一点。在示例id列中隐藏了,但我在View选项的beforeShowFormafterclickPgButtons事件处理程序中显示了信息:

$("#list").jqGrid('navGrid','#pager',
                  {add:false,edit:false,del:false,view:true,search:false},
                  {}, // edit options
                  {}, // add options
                  {}, // del options
                  {}, // search options
                  {   // vew options
                      beforeShowForm: function(form) {
                          $("tr#trv_id",form[0]).show();
                      },
                      afterclickPgButtons: function(whichbutton, form, rowid) {
                          $("tr#trv_id",form[0]).show();
                      }
                  });

答案 2 :(得分:3)

要跟进 J _ 的建议,应用以下方法可以解决问题:

editoptions: { dataInit: function(element) { $(element).attr("readonly", "readonly"); } }

场景#1

  • 字段必须在网格中可见
  • 字段必须以
  • 格式显示
  • 字段必须为只读

<强>解决方案

colModel:[
   {name:'providerUserId',index:'providerUserId', width:100,editable:true, editrules:{required:true}, editoptions:{ dataInit: function(element) { jq(element).attr("readonly", "readonly"); } }},
],

providerUserId在网格中可见,在编辑表单时可见。但是你无法编辑内容。


场景#2

  • 字段必须在网格中不可见
  • 字段必须以
  • 格式显示
  • 字段必须为只读

<强>解决方案

colModel:[
    {name:'providerUserId',index:'providerUserId', width:100,editable:true, editrules:{required:true, edithidden:true}, hidden:true, editoptions:{ dataInit: function(element) { jq(element).attr("readonly", "readonly"); } }},
]

请注意,在两个实例中我都使用jq来引用jquery,而不是通常的$。在我的HTML中,我有以下脚本来修改jQuery使用的变量:

<script type="text/javascript">
    var jq = jQuery.noConflict();
</script>

答案 3 :(得分:1)

隐藏网格列

jQuery("#GridId").jqGrid('hideCol','colName');
相关问题