javascript 调整浏览器窗口大小时调整网格大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9084408/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 05:33:34  来源:igfitidea点击:

resizing of grid when resizing browser window

javascriptslickgrid

提问by Iurii Dziuban

I used a fill whole windowexample as a default. Tried to resize browser window: but area, that is used for grid is the same. Need to reload page so that it fits. How can I archive this without reloading page ?

我使用了一个填充整个窗口的例子作为默认值。试图调整浏览器窗口的大小:但用于网格的区域是相同的。需要重新加载页面以使其适合。如何在不重新加载页面的情况下存档?

Edited

已编辑

Interesting fact that when I change order of columns grid is resized.

有趣的事实是,当我更改列的顺序时,网格会调整大小。

采纳答案by Iurii Dziuban

did this way :

这样做了:

$(window).resize(function () {
    $("#grid").height($("<container for grid>").height());
$(".slick-viewport").height($("#grid").height());
});

Thanks to jQuery and its height() function

感谢 jQuery 及其 height() 函数

回答by biofractal

This works fine for me. Maybe the resizeCanvas()function is a new feature in slick grid.

这对我来说很好用。也许该resizeCanvas()功能是光滑网格中的一个新功能。

The code is CoffeeScript.

代码是 CoffeeScript。

$(window).resize -> grid.resizeCanvas()

回答by sivann

This works better than just changing .slick-viewport height.

这比仅仅改变 .slick-viewport 高度更有效。

$(window).resize(function(){
    var h=$(window).height();
    $('#myGrid').css({'height':(h-65)+'px'});
    grid.resizeCanvas();
});

回答by Unicco

This seems to work just fine:

这似乎工作得很好:

$( window ).resize( function() {
    grid.resizeCanvas();
});