Is it possible to freeze last column to the right side of the grid?
All the demos that I came across shows freezing 1st or 1st & 2nd column to left side of the grid.
I tried using frozen:true
property to only last column in colModel, but its not working.
The current implementation of frozen columns in jqGrid don't allows to freeze last columns to the right side of the grid. So I don't see any simple way to implement your requirements in jqGrid.
The reason of the complexity is in the implementation of frozen columns in jqGrid. The method setFrozenColumns
examine colModel
from the left (from the first index of the colModel
array) at the beginning (see the part of the source code). It finds the max index of colModel
which have frozen: true
property and then makes the copy of the columns of the grid in the separate div. In other words jqGrid take in considerations only first columns of colModel
which have frozen: true
property. All other properties which have frozen: true
will be ignored. Then jqGrid creates always the div with left frozen columns only. So the usage of frozen columns on the right side of the grid not provided.
You are seeing all demos to be freezing only left side columns, because it simply is not possible with jqGrid to freeze right hand side columns or columns that are not adjacent (Try freezing columns 1 and 3 but not 2, this will freeze only column 1. Similarly freezing columns 1, 2 and 4 but not 3 will freeze only columns 1 & 2).
Below the code snippet from jqGrid, which imposes such a rule (refer while loop with comment from left, no breaking frozen
). If you are serious about allowing a right-side column to be frozen, you can try to make modifications to the jqGrid code as per your requirements.
setFrozenColumns : function () {
return this.each(function() {
if ( !this.grid ) {return;}
var $t = this, cm = $t.p.colModel,i=0, len = cm.length, maxfrozen = -1, frozen= false;
// TODO treeGrid and grouping Support
if($t.p.subGrid === true || $t.p.treeGrid === true || $t.p.cellEdit === true || $t.p.sortable || $t.p.scroll )
{
return;
}
if($t.p.rownumbers) { i++; }
if($t.p.multiselect) { i++; }
// get the max index of frozen col
while(i<len)
{
// from left, no breaking frozen
if(cm[i].frozen === true)
{
frozen = true;
maxfrozen = i;
} else {
break;
}
i++;
}