jqGrid-动态设置字幕 [英] jqGrid - setting caption dynamically

查看:37
本文介绍了jqGrid-动态设置字幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在jqGrid定义中设置了caption参数.我想知道是否有一种方法可以根据jqGrid插件所附的表元素的class属性进行动态设置.

I have the caption parameter set in the jqGrid definition. I want to know if there's a way to set it dynamically depending on the class attribute of the table element to which the jqGrid plugin is attached.

HTML 1

<table id="myjqgrid" class="view"></table>
<div id="Pager"></div>

HTML 2

<table id="myjqgrid" class="edit"></table>
<div id="Pager"></div>

JQGrid定义

$("#myjqgrid").jqGrid({
    caption: ""     // this is what I want to set dynamically
})

推荐答案

您可以使用

You can use setCaption method to set new caption on the grid:

var $grid = $('#myjqgrid');
$grid.jqGrid('setCaption', 'newCaption');

如果您需要根据<table>元素的类别设置标题,则代码可能如下所示

If you need to set the caption depend on the class of the <table> element the code can be like the following

if ($grid.hasClass('edit')) {
    $grid.jqGrid('setCaption', 'Edit Caption');
} else if ($grid.hasClass('vew')) {
    $grid.jqGrid('setCaption', 'View Caption');
} else {
    $grid.jqGrid('setCaption', 'Default Caption');
}

关于 setCaption 方法是删除(隐藏)标题:如果创建的网格没有caption参数(或带有caption: ""),则显示的标题.要删除(隐藏)标题,您可以

The only thing which you can't do with respect of setCaption method is to remove (to hide) the caption: the results which you have if you created grid without caption parameter (or with caption: ""). To remove (to hide) the caption you can do

$(">div.ui-jqgrid-titlebar", $grid.closest('div.ui-jqgrid-view')).hide();

$($grid[0].grid.cDiv).hide();

(有关详细信息,请参见答案).

(see the answer for details).

这篇关于jqGrid-动态设置字幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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