Reputation: 2145
Using JQGrid, is it possible to set a default colModel in order to prevent repetition of code? For example instead of
colModel:
[
{name:'name',index:'name',width:80,align:center},
{name:'license',index:'license',width:80,align:center},
{name:'birthday',index:'birthday',width:80,align:center}
]
We could just set width:80
and align:center
to be default values and just do
colModel:
[
{name:'name',index:'name'},
{name:'license',index:'license'},
{name:'birthday',index:'birthday'}
]
Upvotes: 2
Views: 1423
Reputation: 15198
If you have a huge grid (which contains a thousands rows) then assigning align: 'center' in cmTemplate is not very optimal because of EVERY td-tag will contain style-attribute like this:
<td .. style="text-align: center" />
try to calculate overhead of markup size for 1000 rows -> 1000 * 26 byte ~ 25kb
I would prefer to use css-class:
.grid-centered-cells .ui-jqgrid tr.jqgrow td { text-align: center; }
which should be applied to container which cover grid
<div class="grid-centered-cells">
<table id="grid"></table>
</div>
Upvotes: 0
Reputation: 8980
Yes, it's very possible. See this option of jQGrid: cmTemplate
Basically, you can define any default properties you want your colModel
to use.
For example, we will set each column's default width to 80
and the alignment to center
:
$('#myGrid').jqGrid({
cmTemplate: {
width: 80,
align: 'center'
},
// the rest of your jqgrid setup here
});
Now in your colModel
, every column will have a default width of 80
and will be center
aligned. You can of course override the defaults you just setup if need be in a given column.
Upvotes: 2