Stopping columns resizable in jqgrid
Asked Answered
M

2

7

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 the entire grid?

Myriagram answered 18/5, 2011 at 11:38 Comment(0)
G
14

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.

Gregson answered 18/5, 2011 at 16:20 Comment(5)
You are really great in jqgrid. I'll give a try and see how things work, before that I'll upgrade jqgrid from 3.8.2 to 4.0.Myriagram
I can't able to upgrade successfully :( facing many issues here and there. Is there any way we can do this in 3.8.2?Myriagram
@Vijaya Anand: I wrote in my answer that column templates are suported already in jqGrid 3.8.2. So you can just add cmTemplate:{resizable:false} parameter in your current grid an your problem should be solved.Gregson
@Vijaya Anand: Do you have any success in the usage of the column templates?Gregson
@Oleg: There is formatter twice in Date template sample: formatter:'date', formatter:'date'Cellist
C
0

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']} };
Crawly answered 22/8, 2012 at 21:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.