why doesn’t Jqgrid frozen column seem to work with filter rows and filter heading?

I analysed your problem and created the demo which demonstrate how the problem can be solved. The demo produces the grid with the frozen first column:

enter image description here

I found some bugs in the current (version 4.3.1) implementation of frozen columns in jqGrid and will post later my suggestions how to fix there to trirand. The problems are the following:

One can sees the first problem especially clear in case of datatype: 'local' where the data of the grid will be filled during the grid initialization. See the corresponding demo in which I just called the method setFrozenColumns. One can see the problem on the picture

enter image description here

On can see that only the column header will be frozen, but the grid body inclusive the column with row numbers will be scrolled. How one can see from the next demo it will be enough to call the method _complete directly after calling of setFrozenColumns to fix the problem:

$grid.jqGrid('setFrozenColumns');
$grid[0].p._complete.call($grid[0]);

where $grid is defined as var $grid = $('#list');.

The next problem is that _complete method calculate the position of the fixed part of the column header (saved in $grid[0].grid.fhDiv) and the fixed part of the grid body (saved in $grid[0].grid.fbDiv) only using the height of the standard grid’s caption (grid title). So if your use setCaption to change the caption you can have “frozen” dives in the wrong position. The call of _complete method after the setCaption will not fix the problem and one still have the results like on the demo:

enter image description here

To fix the problem I wrote very simple function fixPositionsOfFrozenDivs

var fixPositionsOfFrozenDivs = function () {
        if (typeof this.grid.fbDiv !== "undefined") {
            $(this.grid.fbDiv).css($(this.grid.bDiv).position());
        }
        if (typeof this.grid.fhDiv !== "undefined") {
            $(this.grid.fhDiv).css($(this.grid.hDiv).position());
        }
    };

which fix the position of the frozen dives.

At the end I changed a little the implementation of loadComplete to the following:

loadComplete: function () {
    var $this = $(this), newCapture = "", filters, rules, rule, op, i, iOp,
        postData = $this.jqGrid("getGridParam", "postData"),
        isFiltering = $this.jqGrid("getGridParam", "search");

    if (isFiltering === true && typeof postData.filters !== "undefined") {
        filters = $.parseJSON(postData.filters);
        newCapture = "Filter: [";
        rules = filters.rules;
        for (i = 0; i < rules.length; i++) {
            rule = rules[i];
            op = rule.op;  // the code name of the operation
            iOp = $.inArray(op, arOps);
            if (iOp >= 0 && typeof $.jgrid.search.odata[iOp] !== "undefined") {
                op = $.jgrid.search.odata[iOp];
            }
            newCapture += rule.field + " " + op + " '" + rule.data + "'";
            if (i + 1 !== rules.length) {
                newCapture += ", ";
            }
        }
        newCapture += "]";
    }
    $this.jqGrid("setCaption", newCapture);
    fixPositionsOfFrozenDivs.call(this);
}

where the array arOps are defined as

var arOps = ["eq", "ne", "lt", "le", "gt", "ge", "bw", "bn", "in", "ni", "ew", "en",
             "cn", "nc"];

As the result one will have the demo which I referenced at the beginning of my answer. If you would type some filter in the searching filter toolbar or in the advanced searching dialog the caption of the grid will be changed (like in your original example), but all frozen dives will have the correct position.

Leave a Comment