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 modifying 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
somewhere in the scope of visibility and then just use in
colModelIn the template you can include any parameters. If the column definition has the same property but with the same value like
the value from the
colModel(width: 100in 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:
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
cmTemplateparameter of jqGrid. For exampleYou can use it as additional parameter of jqGrid or set it like any other default parameter with respect of
Read more about the column templates here.