jqGrid - 为一致性而扩展 [英] jqGrid - extending for consistency

查看:16
本文介绍了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 }

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天全站免登陆