3

I have a JQGrid having more than 20 columns. So I kept first 3 columns as frozen and the grid does not have pagination. So as per requirement, we added height of the main div so that user can scroll up/down. Now after adding frozen columns the scroll appears at right side of the grid, and it works when mouse scroll on any un-frozen columns. but the scroll doesn't work when I try to scroll my mouse over the frozen columns. Will appreciate for any clue/solution.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>http://stackoverflow.com/a/20165553/315935</title>
    <meta name="author" content="Oleg Kiriljuk">
    <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/redmond/jquery-ui.css">
    <link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://netdna.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="https://rawgit.com/free-jqgrid/jqGrid/master/css/ui.jqgrid.css">
    <style>
        html, body { font-size: 75%; }
        .ui-datepicker select.ui-datepicker-year,
        .ui-datepicker select.ui-datepicker-month {
            color: black
        }
        .ui-jqgrid >.ui-jqgrid-pager .navtable,
        .ui-jqgrid >.ui-jqgrid-view > .ui-jqgrid-toppager .navtable {
            font-size: 16px;
        }
        .ui-pg-table .ui-pg-button:hover {
            border: 0 none;
            background: #b6dbf7 url("https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/redmond/images/ui-bg_glass_75_d0e5f5_1x400.png") 50% 50% repeat-x;
        }
        .ui-pg-table .ui-pg-table .ui-pg-button:hover {
            font-weight: normal;
            padding: 0;
            margin: 3px;
        }
        .ui-jqgrid .ui-pg-table.navtable .ui-pg-button:hover {
            font-weight: normal;
            padding: 0;
            margin: 2px;
        }
        .ui-jqgrid .jqgrow  .ui-jqgrid-actions > .ui-pg-div:hover {
            margin: 0 1px;
            border: 0 none;
            background: #b6dbf7 url("https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/redmond/images/ui-bg_glass_75_d0e5f5_1x400.png") 50% 50% repeat-x;
        }
    </style>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.js"></script>
    <!--<script src="https://rawgit.com/free-jqgrid/jqGrid/master/js/i18n/grid.locale-en.js"></script>-->
    <script>
        $.jgrid = $.jgrid || {};
        $.jgrid.no_legacy_api = true;
        $.jgrid.useJSON = true;
    </script>
    <!--<script src="../jqGrid/js/jquery.jqGrid.src.js"></script>-->
    <script src="https://rawgit.com/free-jqgrid/jqGrid/master/js/jquery.jqgrid.src.js"></script>
    <!--<script src="http://www.ok-soft-gmbh.com/jqGrid/OK/plugins/jQuery.jqGrid.fontAwesome4.js"></script>
    <script src="http://www.ok-soft-gmbh.com/jqGrid/OK/plugins/jQuery.jqGrid.checkboxFontAwesome4.js"></script>-->
    <script>
    //<![CDATA[
        /*global $ */
        /*jslint browser: true */
        $(function () {
            "use strict";
            var mydata = [
                    { id: "10",  invdate: "2007-10-01", name: "test",   note: "note",   amount: "", tax: "", closed: true,  ship_via: "TN", total: "" },
                    { id: "20",  invdate: "2007-10-02", name: "test2",  note: "note2",  amount: "300.00", tax: "20.00", closed: false, ship_via: "FE", total: "320.00" },
                    { id: "30",  invdate: "2007-09-01", name: "test3",  note: "note3",  amount: "400.00", tax: "30.00", closed: false, ship_via: "FE", total: "430.00" },
                    { id: "40",  invdate: "2007-10-04", name: "test4 test4 test4",  note: "note4",  amount: "200.00", tax: "10.00", closed: true,  ship_via: "TN", total: "210.00" },
                    { id: "50",  invdate: "2007-10-31", name: "test5",  note: "note5",  amount: "300.00", tax: "20.00", closed: false, ship_via: "FE", total: "320.00" },
                    { id: "60",  invdate: "2007-09-06", name: "test6",  note: "note6",  amount: "400.00", tax: "30.00", closed: false, ship_via: "FE", total: "430.00" },
                    { id: "70",  invdate: "2007-10-04", name: "test7",  note: "note7",  amount: "200.00", tax: "10.00", closed: true,  ship_via: "TN", total: "210.00" },
                    { id: "80",  invdate: "2007-10-03", name: "test8",  note: "note8",  amount: "300.00", tax: "20.00", closed: false, ship_via: "FE", total: "320.00" },
                    { id: "90",  invdate: "2007-09-01", name: "test9 test9 test9 test9 test9",  note: "note9",  amount: "400.00", tax: "30.00", closed: false, ship_via: "TN", total: "430.00" },
                    { id: "100", invdate: "2007-09-08", name: "test10", note: "note10", amount: "500.00", tax: "30.00", closed: true,  ship_via: "TN", total: "530.00" },
                    { id: "110", invdate: "2007-09-08", name: "test11", note: "note11", amount: "500.00", tax: "30.00", closed: false, ship_via: "FE", total: "530.00" },
                    { id: "120", invdate: "2007-09-10", name: "test12", note: "note12", amount: "500.00", tax: "30.00", closed: false, ship_via: "FE", total: "530.00" }
                ],
                $grid = $("#list"),
                initDateEdit = function (elem) {
                    $(elem).datepicker({
                        dateFormat: "dd-M-yy",
                        autoSize: true,
                        changeYear: true,
                        changeMonth: true,
                        showButtonPanel: true,
                        showWeek: true
                    });
                },
                initDateSearch = function (elem) {
                    setTimeout(function () {
                        $(elem).datepicker({
                            dateFormat: "dd-M-yy",
                            autoSize: true,
                            changeYear: true,
                            changeMonth: true,
                            showWeek: true,
                            showButtonPanel: true
                        });
                    }, 100);
                },
                integerTemplate = {formatter: "integer", align: "right", sorttype: "integer",
                    editrules: {number: true, required: true},
                    searchoptions: { sopt: ["eq", "ne", "lt", "le", "gt", "ge"] }},
                numberTemplate = {formatter: "number", align: "right", sorttype: "number",
                    editrules: {number: true, required: true},
                    searchoptions: { sopt: ["eq", "ne", "lt", "le", "gt", "ge"] }};

            $.extend(true, $.jgrid.icons, {
                common: "fa fa-lg"
            });

            $grid.jqGrid({
                data: mydata,
                colNames: ["", "Client", "Date", "Amount", "Tax", "Total", "Closed", "Shipped via", "Notes"],
                colModel: [
                    { name: "act", template: "actions", width: 60 },
                    { name: "name", align: "center", width: 65, editrules: {required: true} },
                    { name: "invdate", width: 80, align: "center", sorttype: "date", frozen: true,
                        formatter: "date", formatoptions: { newformat: "d-M-Y", reformatAfterEdit: true }, datefmt: "d-M-Y",
                        editoptions: { dataInit: initDateEdit },
                        searchoptions: { sopt: ["eq", "ne", "lt", "le", "gt", "ge"], dataInit: initDateSearch } },
                    { name: "amount", width: 75, template: "number" },
                    { name: "tax", width: 52, template: "number", autoResizableMinColSize: 40 },
                    { name: "total", width: 60, template: "number" },
                    {name: "closed", width: 70, align: "center", formatter: "checkboxFontAwesome4", //formatter: "checkbox",
                        edittype: "checkbox", editoptions: {value: "Yes:No", defaultValue: "Yes"},
                        stype: "select", searchoptions: { sopt: ["eq", "ne"], value: ":Any;true:Yes;false:No" } },
                    {name: "ship_via", width: 105, align: "center", formatter: "select",
                        edittype: "select", editoptions: { value: "FE:FedEx;TN:TNT;IN:Intim", defaultValue: "IN" },
                        stype: "select", searchoptions: { sopt: ["eq", "ne"], value: ":Any;FE:FedEx;TN:TNT;IN:IN" } },
                    { name: "note", width: 60, edittype: "textarea" }
                ],
                cmTemplate: { editable: true, autoResizable: true },
                rowNum: 10,
                autoResizing: { compact: true },
                resizeStop: function () {
                    var newWidth = this.grid.newWidth, maxIterations = 3, i;
                    for (i = 0; i < maxIterations; i++) {
                        // resize without shrinking
                        $(this).jqGrid("setGridWidth", newWidth + i, false);
                        if (this.grid.bDiv.offsetHeight <= this.grid.bDiv.clientHeight) {
                            break;
                        }
                    }
                },
                rowList: [5, 10, 20],
                pager: "#pager", // "#pa\\.ger" or "pa.ger"
                //pginput: false,
                //pgbuttons: false,
                viewrecords: true,
                //gridview: false,
                iconSet: "fontAwesome",
                toppager: true,
                toolbar: [true, "both"],
                footerrow: true,
                multiselect: true,
                rownumbers: true,
                //direction: "rtl",
                //recordpos: "left",
                //cellEdit: true,
                //beforeSaveCell: function (rowid, name, value, iRow, iCol) {
                //    var cm = this.p.colModel[iCol];
                //    return cm.formatter !== "date" ? value : $.unformat.date.call(this, value, cm);
                //},
                sortname: "invdate",
                sortorder: "desc",
                resizeDblClick: function (iCol, cm) {
                    //alert("DblClick on the column resizer of the column \"" + cm.name + "\"");
                    //autoResizeColumn.call(this, iCol);
                },
                onSelectRow: function (rowid, stat, e) {
                    return;
                },
                inlineEdit: {
                    keys: true
                },
                //viewsortcols: [true, "horizontal", false], // [true, "vertical", false] or [true, "vertical", false]
                //subGrid: true,
                subGridRowExpanded: function (subgridDivId, rowId) {
                    $("#" + $.jgrid.jqID(subgridDivId)).html("<em>simple subgrid data for the row with id=" + rowId + "</em>");
                },
                caption: "Demonstration of the usage sortable:true and frozen formatter: \"actions\"",
                width: 500,
                sortable: true,
                height: 200,
                shrinkToFit: false,
                autoresizeOnLoad: true
            });
            //$grid.jqGrid("setFrozenColumns");
            $grid.jqGrid("navGrid", "#pager", {view: true, cloneToTop: true/*, position: "right"*/})
            .jqGrid("inlineNav", "#list_toppager")
            .jqGrid("inlineNav", "#pager")
            .jqGrid("filterToolbar");
            //$grid.jqGrid("destroyFrozenColumns");
            $grid.jqGrid("setFrozenColumns");
            //$grid.trigger("jqGridResetFrozenHeights");
            //$.jgrid.info_dialog($.jgrid.errors.errcap, "Test message", $.jgrid.edit.bClose);
            //$grid.jqGrid("sortableRows");
            //$("#outerDiv").show();
            //$grid.jqGrid("autoResizeAllColumns");
            $grid.jqGrid("gridResize"); // , {handles: "e, w", shrinkToFit: false}
            //var allData = $grid.jqGrid("getRowData");
            
            $(window).on("resize", function() {
                $("table.ui-jqgrid-btable").each(function () {
                    $(this).trigger("jqGridResetFrozenHeights");
                });
            });
        });
    //]]>
    </script>
</head>
<body>
    <div id="outerDiv" style="margin:5px;">
        <table id="list"></table>
        <div id="pager"></div>
    </div>
</body>
</html>
SK.
  • 1,390
  • 2
  • 28
  • 59
  • It has no sense to post information that something not work in jqGrid without posting which version of jqGrid you tried and from which fork of jqGrid ([free jqGrid](https://github.com/free-jqgrid/jqGrid), commercial [Guriddo jqGrid JS](http://guriddo.net/?page_id=103334) or an old jqGrid in version <=4.7)? If you use old jqGrid (in version <=4.7) then it's known that frozen column is buggy implemented. Do you tried with free jqGrid 4.13.4? If you have the same problem then you should *provide the demo*, which reproduces the problem. It's required to fix the bug if it exist. – Oleg Sep 19 '16 at 19:05
  • @Oleg, I am using jqGrid 4.3.1. Again it is an existing application in production since many years. Ironically I can't upgrade it to latest version. So looking for a fix which can fix this issue. Thanks! – SK. Sep 20 '16 at 00:35
  • A lot of bug fixes are already implemented in later versions of jqGrid and free jqGrid. To be exact I rewrote many parts of the implementation of frozen columns holding the compatibility with old versions. One can't apply the changes to old version 4.3.1. Look at [here](https://github.com/free-jqgrid/jqGrid/compare/v4.3.1...master). You can see that there are more as 2000 commits in jqGrid code since version 4.3.1. **The retro version 4.3.1 (almost 5 years old) is dead.** It is not supported since a long time. No fix will be implemented in the version. – Oleg Sep 20 '16 at 05:02
  • Moreover I don't recommend you to use "virtual scrolling" (neither `scroll: 1` nor `scroll: true` especially together with remote loading of data). The virtual scrolling has many restrictions and many disadvantages. Simple *local* paging works is the recommended way. How many rows and columns need be displayed in the grid? – Oleg Sep 20 '16 at 05:24
  • @Oleg, I agree that 4.3 is very old. but unfortunately it is what it is. And here I am saying about Vertical scrolling (not virtual). Even last night I saw one of example where the same problem is there.http://www.trirand.com/blog/phpjqgrid/examples/functionality/frozen/default.php – SK. Sep 20 '16 at 13:05
  • Probably you don't understand me. Stackoverflow is the place where one try to share **common software development problems**. If you prefer to use some retro version of jqGrid then you have to solve all possible problems *yourself*. You can try to make any changes in your copy of jqGrid 4.3.1, but you will get *new code*, which you have to debug yourself. In the same way you can get free jqGrid 4.13.4, for example, and to verify whether some compatibility problem exist. Probably will will have no issue. In any way I can't help you to fix any bugs in jqGrid 4.3.1. – Oleg Sep 20 '16 at 14:05
  • attach your code. – yash Sep 21 '16 at 09:33
  • @Oleg, Added code now. Basically I just edited the height in below example. http://www.ok-soft-gmbh.com/jqGrid/OK/FontAwesome4Large-borderlessOnHover2-frozen.htm – SK. Sep 21 '16 at 14:39
  • @yash, Added code – SK. Sep 21 '16 at 14:39
  • @Sudhir: Sorry, but it seems I don't understand what you mean. You wrote: "I try to scroll my mouse over the frozen columns". Frozen div has no scrollbar. What you mean under "scroll my mouse"? Do you use touch screen, mousewheel or something like that? Is it your issue that you want to be able to make vertical scroll *without usage of scrollbar* if the mouse is over frozen part of the grid? – Oleg Sep 21 '16 at 16:48
  • @Oleg: Ok, I am sorry if I am not clear. So here is the problem. When I scroll up/down the mouse wheel on any unfrozen columns the grid data is scrolling. But if I scroll the moose wheel on any frozen column, scroll does not work. – SK. Sep 21 '16 at 17:57

2 Answers2

2

If I correctly understand the problem, then you need to use the mouse wheel on frozen columns. Do do this you can add the following code somewhere after calling of setFrozenColumns:

$($grid[0].grid.fbDiv).bind("mousewheel DOMMouseScroll", function (e) {
    $grid[0].grid.bDiv.scrollTop -= e.type === "mousewheel" ?
        e.originalEvent.wheelDelta / 10 :
        -e.originalEvent.detail * 6;
});

It should work, but I'm sure that the calculation of the value of delta shoule be improved. I will consider to make the changes in the main code of setFrozenColumns to do the same automatically (inside of free jqGrid code).

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • You are a life saver. It work so nice. Even it worked in 4.3.1 and IE 5 (which my client is using. Actually they are using the latest version of IE. But not sure why they wrote X-UA-Compatible" content="IE=5"). If Change to IE-edge then all UI look n feel changes. So no one is touching to upgrade it to edge.. But your solution work great. – SK. Sep 21 '16 at 19:53
  • @Sudhir: You are welcome! I simplified the code posted previously. – Oleg Sep 21 '16 at 19:54
  • @Sudhir: I posted [the changes](https://github.com/free-jqgrid/jqGrid/commit/e8663517ec843ed4bc6efbe0e922a1caede0fe1e) to the main code of free jqGrid. Thus the next version which I plan to publish soon will have support of mousewheel/DOMMouseScroll in `setFrozenColumns` out of the box. You should *remove* your custom event handler described in my answer after update to the next version. – Oleg Sep 25 '16 at 21:16
1

Add following style on your page, that worked for me.

.frozen-bdiv {
    pointer-events: none;
}
Umesh
  • 11
  • 1