0

I'm trying to fix the row height of frozen columns of JQGrid using this article. I have been trying get it to work since couple of days now. I was succeeded up to some extend as grid loads properly but still I'm having issue when re-sizing the column headers.

Only the modification that I have done to the original code is that adding following condition to the fixPositionsOfFrozenDivs function.

if (this.grid !== undefined) { }

Steps to Reproduce the Problem:

  1. Load the grid.
  2. Try to reduce the width of a column header which allows frozen column's height to be re-sized.

Following is my code:

$.jgrid.no_legacy_api = true;
$.jgrid.useJSON = true;

//<![CDATA[
/*global $ */
/*jslint browser: true, nomen: true */
$(document).ready(function () {
    var budgetType = $('#IntBudgetType').val();
    var budgetExportJQGridDefaults = {
        colNames: ['Item Control No', 'Budget Revision'],
        shrinkToFit: false,
        colModel: [
            {
                name: 'ItemCode', index: 'ItemCode', search: true, width: 190, cellattr: makeCellContentWrap, frozen: true, searchoptions: {
                    sopt: jqGridSearchOperationsFor.String,
                },
                searchrules: jqGridSearchRulesFor.DefaultMandatory
            },
            {
                name: 'BudgetRevision', index: 'BudgetRevision', search: true, width: 120, searchtype: 'number', cellattr: makeCellContentWrap, searchoptions: {
                    sopt: jqGridSearchOperationsFor.Number
                },
                searchrules: jqGridSearchRulesFor.PositiveIntMandatory
            },
        ],
        pager: '#BudgetExportGridPager',
        rowNum: paramFromView.PageSize,
        sortname: paramFromView.SortName,
        sortorder: paramFromView.SortOrder,
        url: paramFromView.Url,
        afterInsertRow: afterInsert,
        loadComplete: function () {
            fixPositionsOfFrozenDivs.call(this);
        }

    };
    //Add filter only if it's available (an attempt to fire searchrules validations when loading)
    if (paramFromView.hasFilter) {
        budgetExportJQGridDefaults = $.extend({}, budgetExportJQGridDefaults, {
            postData: {
                filters: paramFromView.filterStr
            },
            search: paramFromView.hasFilter
        })
    }
    var budgetExportJQGridSearchDefaults = {

    };

    budgetExportJQGridDefaults = $.extend({}, jqGridAppDefaults, budgetExportJQGridDefaults);
    budgetExportJQGridSearchDefaults = $.extend({}, jqGridSearchDefauls, budgetExportJQGridSearchDefaults);

    $('#BudgetExportGrid').jqGrid(budgetExportJQGridDefaults).navGrid('#BudgetExportGridPager', jqGridNavGridDefaultParameters,
    {},
    {},
    {},
    budgetExportJQGridSearchDefaults);

    $("#BudgetExportGrid").jqGrid('setFrozenColumns');

    function ResizeGridAfterScreenResize() {
        $('#BudgetExportGrid').jqGrid('setGridWidth', $('#BudgetExportGrid').parents('.main-content').width() - 2);
    }
    function afterInsert(rowid, rowdata) {
        var val = $(this).jqGrid('getCell', rowid, 'Error');;
        if (val != '') {
            $(this).jqGrid('setRowData', rowid, false, 'ui-state-error');
        }

    }

    $(window).resize(function () {
        clearTimeout(this.id);
        this.id = setTimeout(function () {
            ResizeGridAfterScreenResize();
        }, 300);
    });

    //fire 1st time when page has loaded
    ResizeGridAfterScreenResize();

    //});


    'use strict';
    $grid = $("#list"),
    resizeColumnHeader = function () {
        var rowHight, resizeSpanHeight,
            // get the header row which contains
            headerRow = $(this).closest("div.ui-jqgrid-view")
                .find("table.ui-jqgrid-htable>thead>tr.ui-jqgrid-labels");

        // reset column height
        headerRow.find("span.ui-jqgrid-resize").each(function () {
            this.style.height = '';
        });

        // increase the height of the resizing span
        resizeSpanHeight = 'height: ' + headerRow.height() + 'px !important; cursor: col-resize;';
        headerRow.find("span.ui-jqgrid-resize").each(function () {
            this.style.cssText = resizeSpanHeight;
        });

        // set position of the dive with the column header text to the middle
        rowHight = headerRow.height();
        headerRow.find("div.ui-jqgrid-sortable").each(function () {
            var $div = $(this);
            $div.css('top', (rowHight - $div.outerHeight()) / 2 + 'px');
        });
    },
    fixPositionsOfFrozenDivs = function () {
        var $rows;
        if (this.grid !== undefined) {
            if (this.grid.fbDiv !== undefined) {
                $rows = $('>div>table.ui-jqgrid-btable>tbody>tr', this.grid.bDiv);
                $('>table.ui-jqgrid-btable>tbody>tr', this.grid.fbDiv).each(function (i) {
                    var rowHight = $($rows[i]).height(), rowHightFrozen = $(this).height();
                    if ($(this).hasClass("jqgrow")) {
                        $(this).height(rowHight);
                        rowHightFrozen = $(this).height();
                        if (rowHight !== rowHightFrozen) {
                            $(this).height(rowHight + (rowHight - rowHightFrozen));
                        }
                    }
                });
                $(this.grid.fbDiv).height(this.grid.bDiv.clientHeight);
                $(this.grid.fbDiv).css($(this.grid.bDiv).position());
            }

            if (this.grid.fhDiv !== undefined) {
                $rows = $('>div>table.ui-jqgrid-htable>thead>tr', this.grid.hDiv);
                $('>table.ui-jqgrid-htable>thead>tr', this.grid.fhDiv).each(function (i) {
                    var rowHight = $($rows[i]).height(), rowHightFrozen = $(this).height();
                    $(this).height(rowHight);
                    rowHightFrozen = $(this).height();
                    if (rowHight !== rowHightFrozen) {
                        $(this).height(rowHight + (rowHight - rowHightFrozen));
                    }
                });
                $(this.grid.fhDiv).height(this.grid.hDiv.clientHeight);
                $(this.grid.fhDiv).css($(this.grid.hDiv).position());
            }
        }
    },
    fixGboxHeight = function () {
        var gviewHeight = $("#gview_" + $.jgrid.jqID(this.id)).outerHeight(),
            pagerHeight = $(this.p.pager).outerHeight();

        $("#gbox_" + $.jgrid.jqID(this.id)).height(gviewHeight + pagerHeight);
        gviewHeight = $("#gview_" + $.jgrid.jqID(this.id)).outerHeight();
        pagerHeight = $(this.p.pager).outerHeight();
        $("#gbox_" + $.jgrid.jqID(this.id)).height(gviewHeight + pagerHeight);
    };


    $grid.jqGrid('gridResize', {
        minWidth: 450,
        stop: function () {
            fixPositionsOfFrozenDivs.call(this);
            fixGboxHeight.call(this);
        }
    });
    $grid.bind("jqGridResizeStop", function () {
        resizeColumnHeader.call(this);
        fixPositionsOfFrozenDivs.call(this);
        fixGboxHeight.call(this);
    });
    resizeColumnHeader.call($grid[0]);
    $grid.jqGrid('setFrozenColumns');
    $grid.triggerHandler("jqGridAfterGridComplete");
    fixPositionsOfFrozenDivs.call($grid[0]);
});
//]]>

This is how it displays when re-sizing column headers.

enter image description here

What am I doing wrong here?

Community
  • 1
  • 1
ecasper
  • 489
  • 1
  • 10
  • 30

1 Answers1

1

Try the following demo. Does it have the same problem? If you can reproduce the problem here then please describe the full test case (how the problem could be reproduced step by step).

UPDATED: The code which you posted seems be combination of an old code with the code from my demo. The problem exist in the line $grid = $("#list"). I use in my demo the grid with id="list", but you use the grid with id="BudgetExportGrid". So $grid.bind("jqGridResizeStop", ...) is not work. You should just use the correct id and the problem with resizing should be fixed.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Tried it, Still the problem seem to exist. However I cannot reproduce the issue on your demo site. It seems the problem is that, first div doesn't get disappeared when re sizing column headers. The strange thing is that when I open the developer tools on the browser, class="frozen-bdiv ui-jqgrid-bdiv" disappears and row heights of the frozen column appears correctly. – ecasper Nov 18 '14 at 14:15
  • 1
    @ecasper: I could help you only if you provide the demo which can be used to reproduce the problem. The only thing which you can try to do is to set `z-index` on `fhDiv`: `$($("#BudgetExportGrid")[0].grid.fhDiv).css("z-index", "1");`. The expression `$("#BudgetExportGrid")[0].grid.fhDiv` is the DOM of div with frozen headers. One should set some large enough "z-index" value. It seems that "1" could be enough. – Oleg Nov 18 '14 at 14:47
  • That didn't work either. I emailed you the login details to demo site. do you think you can have a look? Thanks in advance! – ecasper Nov 18 '14 at 16:26
  • 1
    @ecasper: I debugged the code and have found very simple typing error: see **UPDATED** part of my answer. – Oleg Nov 18 '14 at 19:30