Stopping columns resizable in jqgrid

后端 未结 2 1586
渐次进展
渐次进展 2020-11-22 02:06

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 t

相关标签:
2条回答
  • 2020-11-22 02:23

    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.

    I explain it on an example. If you define additional jqGrid parameter

    cmTemplate:{resizable:false}
    

    then your problem will be solved.

    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.

    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},
            ...
        ]
        ...
    });
    

    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.

    0 讨论(0)
  • 2020-11-22 02:31

    Template works great for me:

     { name: 'quantity_warehouse', index: 'quantity_warehouse', template: intColTemplate, width: '70' },
    
     { name: 'status', index: 'status', align: 'left', template: stringColTemplate, width: '90' },
    
     { name: 'snapshot_at', index: 'snapshot_at', template: dateColTemplate },
    
     { name: 'applied_at', index: 'applied_at', template: dateColTemplate },
    

    JS:

    var dateColTemplate = { align: 'left', search: true, stype: 'text', width: '70', datefmt: 'm/d/y', formatter: 'date', formatoptions: { srcformat: 'm/d/y', newformat: 'm/d/Y' }, sorttype: 'date', searchrules: { required: true, date: true }, searchoptions: { sopt: ['eq', 'ge', 'le'],
    
        dataInit: function (el) {
            $(el).datepicker({ changeYear: true, changeMonth: true, showButtonPanel: true });
        }
    }
    };
    var intColTemplate = { align: 'left', search: true, stype: 'text', searchoptions: { sopt: ['eq', 'ge', 'le']} };
    var stringColTemplate = { align: 'left', search: true, stype: 'text', searchoptions: { sopt: ['bw', 'cn']} };
    
    0 讨论(0)
提交回复
热议问题