jQuery JQGrid-如何设置网格标题单元格的对齐方式? [英] Jquery JQGrid - How to set alignment of grid header cells?

查看:621
本文介绍了jQuery JQGrid-如何设置网格标题单元格的对齐方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在jqgrid中对齐网格列标题?例如,左对齐右还是居中?

在jqrid文档中 http://www.trirand.com/jqgridwiki/doku.php?id = wiki:colmodel_options 它说:

align: Defines the alignment of the cell in the Body layer, not in header cell. 
Possible values: left, center, right.

请注意,它说不在标题单元格中".如何为标题单元格(网格标题单元格)执行此操作?该文档没有提及这个小细节....

解决方案

更改列标题对齐方式的最佳文献记录方法是使用jqGrid的setLabel方法(请参见

您还可以在CSS中定义一些类,并根据setLabel方法将其设置为列标题.

通过选择函数'setLabel'的名称,是因为您无法定义jqGrid的colNames参数,但可以使用colModel中的其他'label'选项来定义其他列标题作为'name'值.

已更新:您可以使用类来定义'text-align''padding'.只需尝试

.textalignright { text-align:right !important; }
.textalignleft { text-align:left  !important; }
.textalignright div { padding-right: 5px; }
.textalignleft div { padding-left: 5px; }

grid.jqGrid ('setLabel', 'Name', '', 'textalignright');
grid.jqGrid ('setLabel', 'Description', '', 'textalignleft');

(我将5px定义为填充以更好地查看结果.您可以选择填充的值,这种情况下您会发现更好).

Is it possible to align grid column headers in jqgrid? eg align left right or center?

In the jqrid documents http://www.trirand.com/jqgridwiki/doku.php?id=wiki:colmodel_options it says:

align: Defines the alignment of the cell in the Body layer, not in header cell. 
Possible values: left, center, right.

Note that it says "not in the header cell". How can I do this for the header cell (grid title cell)? The documentation fails to mention this little detail....

解决方案

The best documented way to change column header alignment is the usage of setLabel method of jqGrid (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:methods).

You can change alignment of the column identified by 'name': 'Name' with the following code:

grid.jqGrid ('setLabel', 'Name', '', {'text-align':'right'});

With the code

grid.jqGrid ('setLabel', 'Name', 'Product Name', {'text-align':'right'},
             {'title':'My ToolTip for the product name column header'});

you can change the header name to 'Product Name' and set 'My ToolTip for the product name column header' as a tool tip for the corresponding column header.

You can also define some classes in your CSS and set it for the column headers also with respect of setLabel method.

By the way the name of the function 'setLabel' is choosed because you can not define colNames parameter of the jqGrid, but use additional 'label' option in the colModel to define a column header other as the 'name' value.

UPDATED: You can do able to use classes to define 'text-align' or 'padding'. Just try following

.textalignright { text-align:right !important; }
.textalignleft { text-align:left  !important; }
.textalignright div { padding-right: 5px; }
.textalignleft div { padding-left: 5px; }

and

grid.jqGrid ('setLabel', 'Name', '', 'textalignright');
grid.jqGrid ('setLabel', 'Description', '', 'textalignleft');

(I defined 5px as the padding to see results better. You can choose the padding value which you will find better in your case).

这篇关于jQuery JQGrid-如何设置网格标题单元格的对齐方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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