jqGrid - extending for consistency

前端 未结 1 995
长发绾君心
长发绾君心 2020-12-21 14:38

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. F

相关标签:
1条回答
  • 2020-12-21 15:04

    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 讨论(0)
提交回复
热议问题