JQGrid - frozen column - freeze the column to the right end of the grid

Is it possible to freeze the last column on the right side of the grid?

All the demos that I came across show a freeze of the 1st or 1st and 2nd columns on the left side of the grid.

I tried to use the frozen:true property only for the last column in colModel, but it does not work.

+5
source share
2 answers

The current implementation of frozen columns in jqGrid does not allow you to freeze the last columns on the right side of the grid. Therefore, I do not see a simple way to implement your requirements in jqGrid.

The reason for the difficulty is to implement frozen columns in jqGrid. The setFrozenColumns method setFrozenColumns consider the colModel on the left (from the first index of the colModel array) at the beginning (see part of the source code). It finds the maximum colModel index, which has the frozen: true property, and then makes a copy of the grid columns in a separate div. In other words, jqGrid only considers the first colModel columns that have the frozen: true property. All other properties that have frozen: true will be ignored. Then jqGrid always creates a div with only left frozen columns . Thus, the use of frozen columns on the right side of the grid is not provided.

+3
source

You see that all the demos freeze only the columns on the left side, because it is simply impossible with jqGrid to freeze columns or columns of the right side that are not adjacent (try to freeze columns 1 and 3, but not 2, this will freeze only column 1. Similarly, freezing columns 1, 2 and 4, but not 3, only columns 1 and 2) will freeze.

Below is a piece of code from jqGrid that imposes such a rule (see while loop with comment from left, no breaking frozen ). If you are serious about allowing freezing on the right column, you can try making changes to the jqGrid code to suit your requirements.

 setFrozenColumns : function () { return this.each(function() { if ( !this.grid ) {return;} var $t = this, cm = $tpcolModel,i=0, len = cm.length, maxfrozen = -1, frozen= false; // TODO treeGrid and grouping Support if($tpsubGrid === true || $tptreeGrid === true || $tpcellEdit === true || $tpsortable || $tpscroll ) { return; } if($tprownumbers) { i++; } if($tpmultiselect) { 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++; } 
+1
source

Source: https://habr.com/ru/post/1209460/


All Articles