jqGrid horizontal scrollbar at top by header

后端 未结 1 1231
情歌与酒
情歌与酒 2020-12-11 09:36

Just curious if anyone knows of a way to add a horizontal scrollbar to the top of jqGrid (like just under or above the headers)? I\'m using frozen columns and height:auto b

相关标签:
1条回答
  • 2020-12-11 10:01

    I find your question interesting. I invested some time and created the following demo which demonstrates how your requirements could be implemented. It displays

    enter image description here

    where one can use both horizontal scrollbars on the top or on the bottom of the grid. I used the answer as the basis of creating the top scroll bar. Additionally I included the part of code which fixed the size and position of all jqGrid dives in case if the user uses zoom in the web browser.

    The most important part of the code of my answer I included below:

    var $grid = $("#list");
    // create the grid with some frozen columns
    $grid.jqGrid({
        ....
    });
    
    var $gview = $grid.closest(".ui-jqgrid-view"),
        $topToolbar = $gview.find(">.ui-userdata"),
        $bdiv = $grid.closest(".ui-jqgrid-bdiv"),
        resetTopToolbarHeight = function () {
            var scrollbarHeight = 18; // some test value
            $topToolbar.find(">div").height(scrollbarHeight);
            $topToolbar.css("border-top", "0").css("height", "auto");
            scrollbarHeight = $topToolbar.height() - scrollbarHeight;
            $topToolbar.find(">div").height(scrollbarHeight);
            $topToolbar.height(scrollbarHeight);
            fixPositionsOfFrozenDivs.call($grid[0]);
        };
    // insert empty div in the top toolbar and make its width
    // the same as the width of the grid
    $topToolbar.css({ overflowX: "scroll", overflowY: "hidden"})
        .append($("<div>").width($grid.width()));
    // set the height of the div and the height of toolbar
    // based on the height of the horizontal scrollbar
    resetTopToolbarHeight();
    // detect scrolling of topbar
    $topToolbar.scroll(function () {
        // synchronize the srollbar of the grid
        $bdiv.scrollLeft($(this).scrollLeft());
    });
    // detect scrolling of the grid
    $bdiv.scroll(function () {
        // synchronize the srollbar of the toppbar
        $topToolbar.scrollLeft($(this).scrollLeft());
    });
    // detect zoop of the page and adjust the
    $(window).on("resize", function () {
        resetTopToolbarHeight();
        fixPositionsOfFrozenDivs.call($grid[0]);
    });
    

    Other parts of the code I get from my old answers about the usage of frozen columns.

    0 讨论(0)
提交回复
热议问题