如何在公共位置进行更新以更改 jqGrid 的 header 对齐方式

How to do update in a common place to change the header alignment of jqGrid

我们正在开发一个使用 jqGrid 来显示数据的网站。现在我们有一个要求将网格 header 文本对齐方式更改为左对齐。 我们在很多地方都在使用 jqGrid。

我们已经尝试了以下方法来更改对齐方式并且工作正常。

$("#tableName").jqGrid('setLabel', 'ColumnName', '', {'text-align':'left'});

但是正如我所说,这个应用程序在很多地方都使用了 jqGrid。因此,要更改对齐方式,我们必须在许多地方进行更新。

由于在我们使用jqGrid的所有地方都需要做这个改动,请问有没有什么公共的地方可以做这个更新,这样我们就可以避免很多地方的更新。

jqGrid 版本 - 4.5.4

提前致谢。

请始终写明,您使用的是哪个版本的 jqGrid 以及来自哪个分支(free jqGrid, Guriddo jqGrid JS 或版本 <=4.7 的旧 jqGrid)。

我开发 free jqGrid fork of jqGrid since more as one year and have published many versions of the fork. The current version is 4.12.1. Already in the first version of free jqGrid (see the readme 4.8) I included some simple extensions which you need: new property labelAlign which allows to align column headers. Possible values are "left", "right" and "likeData". No value means center alignments. The old demo 演示新 labelAlignlabelClasses 属性的用法。

如果你需要

cmTemplate: { labelAlign: "left" }

您可以使用 $.jgrid.defaults 设置值:

$.extend(true, $.jgrid.defaults, {cmTemplate: { labelAlign: "left" }});

https://jsfiddle.net/OlegKi/h3ksrjmp/