【问题标题】:Kendo Grid auto resize by number of rowsKendo Grid 按行数自动调整大小
【发布时间】:2018-01-03 09:33:06
【问题描述】:

无论窗口大小如何变化,如何在剑道网格中显示固定数量的行? 无论窗口大小如何,我都需要显示 10 行。 为此,我需要重新计算行数并仅在网格内显示 10 行。我的要求是计算要在网格中正确显示的行。 (事实上​​,我在网上搜索过,似乎找不到任何例子/文章,如果你有任何也请与我分享)。我目前的解决方案在我看来没有错误,但仍然不正确??? .有人可以帮我找出错误并纠正我吗?此外,如果我在网格上方插入一些项目,包装器和数据项(网格)将完全不正确。

我需要一些关于这个问题的见解和/或代码示例。 非常感谢您的帮助。

我当前调整网格大小的代码如下:

function resizeGrid() {
    var gridElement = $("#grid"),
        dataArea = gridElement.find(".k-grid-content"),
        gridHeight = gridElement.innerHeight(),
        otherElements = gridElement.children().not(".k-grid-content"),
        otherElementsHeight = 0;
    otherElements.each(function(){
        otherElementsHeight += $(this).outerHeight();
    });
    dataArea.height(gridHeight - otherElementsHeight);
}

function resizeWrapper() {
     $("#outerWrapper").height($('#body').innerHeight());
    }

并调用它们的函数:

  $(window).resize(function() {
    resizeWrapper();
    resizeGrid();
  });

这是我的数据源和架构:

 $(document).ready(function() {
    $(window).trigger("resize");
        $("#grid").kendoGrid({     
      dataSource: {
                            data: [

                              { userId: 11111, No: 1, isActive:true, date: new Date('12/12/2005 12:30 AM'), from: 'A', sm: 'testing', art: 'Shipped on', due: new Date('12/19/2005 11:30 PM')},
      { userId: 22340, No: 2, isActive:true, date: new Date('12/12/2005 12:30 AM'), from: 'A', sm: 'test0', art: 'Shipped on', due: new Date('12/19/2005 11:30 PM')},
      .....
      ],

                    schema: {
                        model: {
                            fields: {
                              userId: { editable: true },
                              date: { filterable: { ui: "datetimepicker"}},
                              isActive:false,
                              No: { editable: true }
                            }
                        }
                    },
                    pageSize: 10
                },

                sortable: true,
                reorderable: true,
                scrollable: true,
                resizable: true,
                filterable: true,
                columnMenu: true,
                pageable: {
                            input: true,
                            numeric: false
                        },               
                columns: [
                  { field: 'No' ,width: 50 },
    { field: 'userId', title: 'ID', template:"<span class=ul>#=userId#</span> </br> <span class='pie'>1/5</span>", width:60 }      ,  
                  { field: "isActive", 
            headerTemplate: '!',
            template: '<span class="k-icon k-i-circle Unicode: e308" style="color: green; font-size: 28px;"></span> </br> <div class="div1"></div>', filterable:false , width: 40  },
    ......              
    ]        
    });        
  });

这是我的剑道链接:http://dojo.telerik.com/aviQU/6

【问题讨论】:

    标签: kendo-ui kendo-grid


    【解决方案1】:

    为什么不告诉网格使用 10 的页面大小?无需重新计算尺寸。

    在配置网格时设置数据源的页面大小。

    或者您是否在某个位置设置 (CSS/JS) 导致其调整大小的网格高度?

    【讨论】:

    • 是的,这样更直接,我可以通过将页面大小设置为数据源来轻松控制行号(在我的代码中我也这样做了)但这是要求之一(按行计算数字)让我完成。我找到了这个链接:github.com/angular-ui/ui-grid/issues/1735 但它是有角度的,我无法理解在我的道场中应用。但我想这很相似。目前我没有在 CSS/JS 中设置任何自定义高度。
    • @NewBie 在这种情况下,我认为您需要修改问题。目前它说无论窗口大小都需要 10 行。但听起来10是个例子:你需要告诉我们在问题中的要求是什么(cmets中的内容太容易错过了)。
    • 嗨,Richard,我已经发布了包含全部要求的新问题。 stackoverflow.com/questions/48107051/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-22
    • 2017-07-10
    • 1970-01-01
    • 2019-11-20
    • 2019-05-01
    • 2018-09-16
    相关资源
    最近更新 更多