jqGrid-扩展以保持一致性 [英] jqGrid - extending for consistency

查看:80
本文介绍了jqGrid-扩展以保持一致性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将jqGrid用于很多只有少量应用程序特定列类型的网格,并且我想创建一种实现一致性的方法.例如,我希望显示行的合规性状态的所有列都具有某种格式,以某种方式对齐,具有特定的搜索选项等.因此,不要像这样的colmodel条目:

I would like to use jqGrid for a great many grids that have only a small set of application-specific column types, and I would like to create a way to enforce consistency. For example, I want all my columns that show the compliance status of a row to have a certain format, be aligned a certain way, have specific search options, etc. So instead of having a colmodel entry like this:

{ name: 'ABC', width: 80, align: 'center', stype: "select", 
              searchoptions: { value: "1:Compliant;0:Not Compliant"} }

我想要一个这样的人:

{ name: 'ABC', width: 80, mytype: compliancestatus }

我要编写的状态是合规性状态.

where compliancestatus is a function I would write.

这种事情是否可能-无需修改jqGrid源代码?如果是这样,有人可以指出我这种扩展类型的例子吗?

Is this kind of thing possible - without modifying the jqGrid source code? If so, can someone point me to an example of this type of extension?

推荐答案

因为jqGrid 3.8.2是列模板,所以受支持.

Since jqGrid 3.8.2 are column templates supported.

您可以仅定义一个例子

var compliancestatus = {
        width: 80,
        align: 'center',
        stype: "select", 
        searchoptions: { value: "1:Compliant;0:Not Compliant" }
    };

在可见范围内的某个位置,然后在colModel

somewhere in the scope of visibility and then just use in colModel

{ name: 'ABC', template: compliancestatus }

在模板中,您可以包含任何参数.如果列定义具有相同的属性,但具有相同的值,例如

In the template you can include any parameters. If the column definition has the same property but with the same value like

{ name: 'ABC', width: 100, template: compliancestatus }

将使用colModel中的值(在这种情况下为width: 100).

the value from the colModel (width: 100 in the case) will be used.

提出了建议功能,我本人对此进行了大量使用.例如,我有很多网格,其中有很多带有复选框的列.在这种情况下,我使用以下模板:

I suggested the feature some time before and I use it intensively myself. For example I have many grids having many columns with checkboxes. I use the following template in the case:

mySettings.templateCheckbox = {
    formatter: 'checkbox', align: 'center', width: 20,
    edittype: 'checkbox', editoptions: { value: "1:0" },
    stype: "select", searchoptions: { sopt: ['eq', 'ne'], value: ":Any;1:Yes;0:No" }
};

以同样的方式,我定义了许多其他模板,这些模板减少了网格的代码并改善了常见网格样式的管理.

In the same way I defined many other templates which reduce the code of grids and improve managing of the common grid style.

如果要更改所有列的某些通用默认设置 ,则可以使用jqGrid的cmTemplate参数.例如

If you want to change some common default settings for all columns you can use cmTemplate parameter of jqGrid. For example

cmTemplate: { align: 'center' }

您可以将其用作其他 jqGrid的参数或像其他任何默认参数一样将其设置为

You can use it as additional parameter of jqGrid or set it like any other default parameter with respect of

$.extend($.jgrid.defaults, {
    cmTemplate: { align: 'center' }
});

此处了解更多有关列模板的信息.

Read more about the column templates here.

这篇关于jqGrid-扩展以保持一致性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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