停止在 jqgrid 中调整大小的列 [英] Stopping columns resizable in jqgrid
问题描述
如何使 jqgrid 的所有列都不能调整大小?目前我认为每一列我都必须指定属性 { resizable:false }.反正我可以为整个网格指定吗?
How I can make all the columns of jqgrid not resizable? Currently I think every column I've to specify the property { resizable:false }. Is there anyway I can specify for the entire grid?
推荐答案
从 3.8.2 版本开始,jqGrid 支持一项非常有用的功能:列模板.(我称赞这个功能可能不太正确,因为该功能是在 我自己的建议 :-)).该功能仍未真正记录在案,但可以非常轻松地使用.
Starting with version 3.8.2 jqGrid supports one very useful feature: column templates. (It's probably not quite correct from me to praise the feature because the feature was introduced on my own suggestion :-)). The feature is still not really documented, but it can be used very easily.
我用一个例子来解释它.如果你定义了额外的 jqGrid 参数
I explain it on an example. If you define additional jqGrid parameter
cmTemplate:{resizable:false}
那么你的问题就解决了.
then your problem will be solved.
如果您有更多 colModel
项的所有列 中共有的属性,例如 align:'center'
和 cmTemplate
也会帮助您(cmTemplate:{resizable:false, align:'center'}).在 jqGrid 3.8.2 中很小 bug 模板设置的优先级相对于 colModel
的设置,但该 bug 在 jqGrid 4.0.0 中已修复.因此,来自 cmTemplate
的属性可以被解释为 colModel
项目的默认值.
If you have more properties which are common in all columns of colModel
items, for example align:'center'
the cmTemplate
will help you also (cmTemplate:{resizable:false, align:'center'}). In jqGrid 3.8.2 was small bug in priority of template settings relatively to settings from colModel
, but the bug is fixed in jqGrid 4.0.0. So the properties from cmTemplate
can be interpret just as default values for colModel
items.
另外一个版本的jqGrid列模板用法如下:
One more version of usage jqGrid column template is in the form:
var myDateTemplate = {sorttype:'date', formatter:'date',
formatoptions: {newformat:'m/d/Y'}, datefmt: 'm/d/Y',
align:'center', width:80 }
$("list").jqGrid({
colModel: [
...
{name:'column1': template:myDateTemplate},
{name:'column2': template:myDateTemplate, width:90},
...
]
...
});
通过这种方式,您可以定义一些模板(如 myDateTemplate
)并在网格(或 gids)的许多地方使用它们.就该功能而言,您可以使您的代码更短、更易读且易于更改.
In the way you can define some templates (like myDateTemplate
) and use there in many places in your grid (or gids). With respect of the feature you can make your code shorter, better readable and easily changeable.
这篇关于停止在 jqgrid 中调整大小的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!