【问题标题】:jqGrid - vertical scrollbar not showingjqGrid - 垂直滚动条不显示
【发布时间】:2015-01-31 07:30:47
【问题描述】:

我正在开发 jquery jqgrid 插件。在这个网格中,我有 1,000,000 条带有scroll: 1 选项的记录。而且我的网格中有rowNum: 10 选项。但只有前 10 行显示在网格和垂直滚动条中丢失。在标题中,我有“从 1,000,000 显示 1-10”字符串。这意味着总数计算是正确的,但我不知道为什么缺少滚动条。谁能帮我解决这个问题?

编辑:我的 jqGrid 版本是:4.6.0。这是我的javascript代码:

 $(document).ready(function() {
            var colModel = [
                {name: "id", width: 200, align: "center", searchoptions: {clearSearch: false}, hidden: true, hiddenlg: true},
                {name: "ordernumber", width: 200, align: "center", searchoptions: {clearSearch: false}},
                {name: "customer.fname", width: 200, align: "center", searchoptions: {clearSearch: false}},
                {name: "customer.lname", width: 200, align: "center", searchoptions: {clearSearch: false}},
            ];
            $("#list").jqGrid({
                url: "/orders/listGrid",
                datatype: "json",
                mtype: "POST",
                colNames: ["", "1", "2", "3"],
                colModel: colModel,
                pager: "#pager",
                rowNum: 10,
                rowList: [10, 20, 30],
                viewrecords: true,
                multiSort: false,
                gridview: true,
                autoencode: true,
                shrinkToFit: false,
                autowidth: true,
                scroll: 1,
                direction: "rtl",
                height: 230,
                caption: "Test",
                hidegrid: false,
                ajaxGridOptions: {
                    contentType: "application/json; charset=utf-8"
                },
                serializeGridData: function(data) {
                    return JSON.stringify(data);
                },

            });
        });

这是我的 html 代码:

<table id="list"></table>
<div id="pager"></div>

【问题讨论】:

  • 您是否在网格中明确指定了height 选项以及"auto" 和"100%" 以外的一些值? 例如,尝试指定height: 230,即足以显示 10 行标准文本。你能发布更多关于你做什么的信息吗?您使用哪个版本的 jqGrid?问题是否只存在于某些特定版本的 jqGrid 中?
  • 感谢您的回复。我会更新我的问题并添加额外的信息。感谢您的关注。

标签: jquery jqgrid scrollbar


【解决方案1】:

问题的存在可能是因为您使用了非常多的行数,而当前的虚拟滚动实现不允许显示如此多的行数。最大行数的确切限制取决于您使用的 Web 浏览器。看看我几年前发布的the bug report。另见the post。

问题如下。 jqGrid 在网格之外使用 div 并尝试将其高度设置为值parseInt(ts.p.records,10) * rowHeight(参见the line),其中rowHeight 是23px。所以 jqGrid 会尝试在你的情况下将height 设置为23000000px,但它不会改变height 的值,并且不会看到垂直滚动条。

大家可以尝试制作一些技巧,比如代码的用法之类的

jsonReader: {
    records: function (obj) {
        // return not so large value of records
        return Math.min(66692, obj.records);
    }
},
loadComplete: function (data) {
    var $self = $(this), p = $self.jqGrid("getGridParam"),
        numberFormat = $.fmatter.util.NumberFormat || $.fmatter.NumberFormat,
        fmt = $.jgrid.formatter.integer || {},
        from = numberFormat(parseInt(p.page,10), fmt),
        to = numberFormat((parseInt(p.page,10)-1)*parseInt(p.rowNum,10) + p.reccount, fmt),
        total = numberFormat(parseInt(data.records,10), fmt); // use correct value

    // fix the displayed row numbers
    $(".ui-paging-info", p.pager)
        .html($.jgrid.format(p.recordtext, from, to, total));
}

见the demo。但是这样的技巧将允许只显示网格的一些第一页。使 jqGrid 真正能够在虚拟滚动的情况下显示大量行 (scroll: 1) 需要重写 jqGrid 代码的某些部分。

我建议您最好使用标准分页而不是虚拟滚动。使用必须使用寻呼机的 First/Previous/Next/Last 按钮,但大多数需要检查 1,000,000 行数据的用户都可以这样做。

告诉信任没有人会滚动超过 1,000,000 行。取而代之的是,需要提供良好的过滤/搜索可能性。例如使用filterToolbar 和advanced searching。设置相应的过滤器后,过滤后的数据可以显示在 1 到 10 页中,这样的数据显示起来真的很有趣。

【讨论】:

  • 感谢您的帮助@Oleg。你的回答很好也很正确。
  • 您说:“需要重写 jqGrid 代码的某些部分。”。 jqGrid 代码的哪些部分应该重写?你能进一步解释一下吗?
  • 我将该代码添加到 jqGrid 选项中。但在网格中显示的 1,000,000 条记录中只有大约 66,000 条。
  • @hamed:不客气!您能否提供一个返回服务器的数据示例?我发布的loadComplete 的代码在data.records 中获得正确 的数据数量,但在jsonReader.records 中通知jqGrid 更多小的值。可能您还有一些其他格式的服务器数据。重写我的意思是重写虚拟滚动实现:populateVisible、updatepager 可能还有其他一些
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-10-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-30
  • 1970-01-01
相关资源
最近更新 更多