开发者

jqGrid - extending for consistency

开发者 https://www.devze.com 2023-04-05 09:36 出处:网络
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 c

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"} }

I would like to have one like this:

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

where compliancestatus is a function I would write.

Is this kind of thing possible - without mod开发者_JAVA百科ifying the jqGrid source code? If so, can someone point me to an example of this type of extension?


Since jqGrid 3.8.2 are column templates supported.

You can just define for example

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

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 }

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.

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

cmTemplate: { align: 'center' }

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消