jQuery 如何删除(或隐藏)jqgrid 中的标题栏?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5284141/
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
How can you remove (or hide) the caption bar in jqgrid?
提问by leora
I see you can add a top caption bar and put a title by using this code:
我看到您可以使用以下代码添加顶部标题栏并放置标题:
jQuery('#grid').setCaption("Title");
Is there anyway, if I have already set a title, to remove the caption bar?
无论如何,如果我已经设置了标题,是否可以删除标题栏?
I tried this but it just removes the text (doesn't remove the whole caption bar).
我试过了,但它只是删除了文本(不会删除整个标题栏)。
jQuery('#grid').setCaption("");
回答by Mujah Maskey
if you want hurry, test
如果你想快点,测试
$(".ui-jqgrid-titlebar").hide();
or if you have multiple grids, then only hide titlebar of $("#grid"), then do
或者,如果您有多个网格,则只隐藏 $("#grid") 的标题栏,然后执行
$("#gview_grid > .ui-jqgrid-titlebar").hide()
回答by Oleg
If you create jqGrid having no title bar (caption: ""
) and examine the grid with respect of Developer Tools or with respect of Firebug you will see the <div>
with the class "ui-jqgrid-titlebar" having <span>
with the class "ui-jqgrid-title" and the anchor with the class "ui-jqgrid-titlebar-close" as the child elements:
如果您创建没有标题栏 ( caption: ""
) 的jqGrid并根据开发人员工具或 Firebug 检查网格,您将看到<div>
类“ui-jqgrid-titlebar”具有<span>
类“ui-jqgrid-title”和以“ui-jqgrid-titlebar-close”类为子元素的锚点:
<div id="gbox_list" class="ui-jqgrid ui-widget ui-widget-content ui-corner-all">
...
<div id="gview_list" class="ui-jqgrid-view">
<div style="display: none;"
class="ui-jqgrid-titlebar ui-widget-header ui-corner-top ui-helper-clearfix">
<a style="right: 0px;" class="ui-jqgrid-titlebar-close HeaderButton"
role="link" href="javascript:void(0)">
<span class="ui-icon ui-icon-circle-triangle-n"></span>
</a>
<span class="ui-jqgrid-title"></span>
</div>
...
So even you create the grid without the title bar jqGrid create all hidden elements of the title bar.
因此,即使您创建没有标题栏的网格 jqGrid 也会创建标题栏的所有隐藏元素。
I looked through the jqGrid code where the caption are created and could find the following fragment
我查看了创建标题的 jqGrid 代码,可以找到以下片段
if(ts.p.caption) {
...
$(".ui-jqgrid-titlebar-close",grid.cDiv).click( function(e){
...
} else {$(grid.cDiv).hide();}
So to have the same results as with the grid initialized with caption: ""
parameter you can do following
因此,要获得与使用caption: ""
参数初始化的网格相同的结果,您可以执行以下操作
var mygrid = jQuery('#list'),
cDiv = mygrid[0].grid.cDiv;
mygrid.setCaption("");
$("a.ui-jqgrid-titlebar-close",cDiv).unbind();
$(cDiv).hide();
You should do unbinding from the minimize button only if you are sure, that the grid will not have the title (caption
) later. The bindings took less resources and do nothing for the hidden grid.
仅当您确定网格以后不会有标题 ( caption
) 时,才应从最小化按钮解除绑定。绑定占用的资源更少,并且对隐藏网格没有任何作用。
So the suggestionof Pravat Maskey just to hide the title is absolutely correct and my investigations only confirm this.
因此,Pravat Maskey 只是隐藏标题的建议是绝对正确的,我的调查仅证实了这一点。