【问题标题】:k-grid-content not scrolling vertically if content overflows如果内容溢出,k-grid-content 不会垂直滚动
【发布时间】:2017-01-12 12:47:20
【问题描述】:

我的剑道 UI 网格有问题。

我增加了网格中的列表,但是在初始加载时,“k-grid-content”不显示滚动条,并且内容比当前显示的要多。

如下所示,scrollable设置为true。

create: function (container) {
        this.container = container;
        $(container).kendoGrid({
            selectable: 'multiple',
            pageable: { refresh: true, buttonCount: 5, input: true },
            scrollable: true,
            navigatable: true,
            filterable: false,
            editable: true,
            resizable: true,
            columns: articleCategoryTab.grid.columns,
            dataBound: articleCategoryTab.events.onGridDataBound
        });
    },

我尝试在 dataBind 事件中编写一些 Javascript,以便根据 browser_height 的某些计算给它一个固定的高度,但这不起作用。

我该如何解决这个问题?

【问题讨论】:

    标签: jquery asp.net kendo-ui kendo-grid


    【解决方案1】:

    我通过将以下内容放在 Kendo UI 网格的 dataBind 事件中来修复它。

    dataBind: function (ds) {
            this.get().setDataSource(ds);
    
            //make k-grid-content scrollable on initial load
            var BROWSER_HEIGHT = $(window).height();
            var diff = $('.container').height() +
            $('#articleManagementTabs').height() +
            $('#categoryArticleNavbar').height() +
            $('#categoryArticlePager').height() +
            $('#previewPaneWrapper').height();
            var difference = BROWSER_HEIGHT - diff - 10;
    
            var gridElement = $("#categoryArticleGrid");
            var dataArea = gridElement.find(".k-grid-content");
            dataArea.height(difference);
            dataArea.css('overflow-y', 'scroll');
    
        },
    

    【讨论】:

      【解决方案2】:

      虽然您已经为您自己的问题提供了答案,但我想我会提供一个我想出的解决方案,用于即时调整网格大小。

      这是我创建的用于调整网格大小的函数,它可以一次性应用于多个不同的网格,并考虑网格中锁定和解锁的列

      function initializeGrid(options)
      {
          if(options === null || options === undefined)
          {
              options = {
                  size: 0.55,
                  gridContentCss: ".k-grid-content",
                  gridLockedContentCss: ".k-grid-content-locked",
                  gridsToResize:[]
              };
          }
      
      
          var windowHeight = $(window).height() * options.size;
      
          if(options.gridsToResize !== null && options.gridsToResize.length > 0 )
          {
              options.gridsToResize.forEach(function (item) {
                  var gridContent = $('#' + item + ' > ' + options.gridContentCss);
      
      
                  var lockedContent = $('#' + item + ' > ' + options.gridLockedContentCss);
      
      
                //  console.log(gridContent, lockedContent);
      
                  gridContent.height(windowHeight);
      
                  if (lockedContent !== null && lockedContent !== undefined) {
                      lockedContent.height(windowHeight);
      
                  }
              }); 
          }
          else 
          {
              var gridContent = $(options.gridContentCss);
              var lockedContent = $(options.gridLockedContentCss);
      
              gridContent.height(windowHeight);
      
              if (lockedContent !== null && lockedContent !== undefined) {
                  lockedContent.height(windowHeight);
      
              }
          }
      
      
      
      }
      

      所以这是在初始 document 就绪事件上调用的,如下所示:

       $(document).ready(function () {
                  initializeGrid(null); 
      }); 
      

      这里是它的演示:http://dojo.telerik.com/ALAnu

      这只是使用一个名为 initializeGrid 的函数,它接受一个选项对象,该对象定义了网格的锁定和解锁部分的 size、grid content css 指标,以及然后是一个 网格 ID 数组,没有要调整大小的散列。如果不存在任何对象,则该函数初始化它自己的该对象版本,并假设此时屏幕上只有一个网格来调整大小。

      这会根据整个窗口大小的百分比计算高度,然后根据此调整网格高度,因此默认情况下,网格将占据可用屏幕高度的 55%。重要的是不要提供初始 height 值,因为这将覆盖上述高度调整机制。

      如果您需要考虑屏幕中的其他elements,这显然可以根据您的需要进行修改。

      【讨论】:

      • 感谢您的努力。
      猜你喜欢
      • 2022-01-17
      • 1970-01-01
      • 1970-01-01
      • 2012-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-26
      相关资源
      最近更新 更多