jqGrid水平滚动条在顶部按标题 [英] jqGrid horizontal scrollbar at top by header

查看:1216
本文介绍了jqGrid水平滚动条在顶部按标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只要好奇,如果有人知道一个方法来添加一个水平滚动条到jqGrid的顶部(像只是在头下或上方)?我使用冻结的列和高度:自动,但是当有很多行,用户必须向下滚动网格水平,不能看到标题...
我做了一些搜索,它看起来喜欢滚动条在大多数情况下很难混乱,但我想我会把它放在那里。



谢谢!

解决方案

我发现你的问题很有趣。我投入了一些时间,并创建了作为创建顶部滚动条的基础。另外,我包括了一些代码,这些代码固定了所有jqGrid潜水的大小和位置,以防万一用户在网络浏览器中使用缩放。



最重要的部分代码我的回答我包括如下:

  var $ grid = $(#list); 
//创建带有一些冻结列的网格
$ 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]);
};
//在顶部工具栏中插入空div,并使其宽度
//与网格的宽度相同
$ topToolbar.css(overflowX:scroll,overflowY:隐藏})
.append($(< div>)。width($ grid.width()));
//根据水平滚动条的高度设置div的高度和工具栏的高度
//
resetTopToolbarHeight();
//检测topbar的滚动
$ topToolbar.scroll(function(){
//同步网格的滚动条
$ bdiv.scrollLeft($(this).scrollLeft ());
});
//检测网格的滚动
$ bdiv.scroll(function(){
//同步toppbar的滚动条
$ topToolbar.scrollLeft($(this)。 scrollLeft());
});
//检测页面的zoop并调整
$(window).on(resize,function(){
resetTopToolbarHeight();
fixPositionsOfFrozenDivs.call grid [0]);
});

我从关于冻结列的使用的旧答案获得的代码的其他部分。 >

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 but when there are lots of rows, the user has to scroll down to scroll the grid horizontally and can't see the headers... I did some searching and it looks like scrollbars are hard to mess with in most cases, but I figured I would just put it out there.

Thanks!

解决方案

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

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.

这篇关于jqGrid水平滚动条在顶部按标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆