javascript - 想要在浏览器窗口最小化或最大化时重置 RadGrid 高度

标签 javascript asp.net c#-4.0 telerik

我有一个 RadGrid。我在 ClientSettings 的 ClientEvents 中看到了诸如 OnGridCreatedOnRowHiding 等事件。我想要一个类似 OnBrowserWindowResize 的方法,以便当用户最小化或最大化浏览器窗口时,会引发一个事件,我可以将 RadGrid 高度设置为某个值。我尝试使用

$(window).resize(function(){..} 

但在里面我找不到我的 RadGrid。请给我一个解决方案

最佳答案

首先,您将 GridView 放入某个 div 中。将属性高度设置为100%!重要。在 JS 函数动态编辑 div 高度时,请尝试遵循此示例,它对我有用。

编辑.css

<style>
  /*Set height 100% !important*/
.grid_style {
    height: 100% !important;
    width: 100% !important;
}

编辑.aspx

<div class="grid_conteiner" id="grid_conteiner" style="height: 500px;">
<telerik:RadGrid RenderMode="Lightweight" ID="RadGrid1" runat="server" GridLines="None" CssClass="grid_style">


</telerik:RadGrid>

编辑 JS headerHeight 值 您需要更改和设置页眉的高度,也对 footerHeight 执行相同的操作。

<script type="text/javascript">
    function getWindowHeight() {
        var functionReturn = 0;

        if ((document.documentElement) && (document.documentElement.clientHeight))
            functionReturn = document.documentElement.clientHeight;
        else if ((document.body) && (document.body.clientHeight))
            functionReturn = document.body.clientHeight;
        else if ((document.body) && (document.body.offsetHeight))
            functionReturn = document.body.offsetHeight;
        else if (window.innerHeight)
            functionReturn = window.innerHeight - 18;

        functionReturn = parseInt(functionReturn);
        if ((isNaN(functionReturn) === true) || (functionReturn < 0))
            functionReturn = 0;

        return functionReturn;
    };


    window.onresize = function(event) {
        var gridC = document.getElementById("grid_conteiner");

        if (gridC != null) {
            //Here set in px height of header
            var headerHeight = 120;
            //Here set in px height of your fooer
            var footerHeight = 80;
            //Here is getting window height
            var winHeight = getWindowHeight();
            //Here is set dynamically height to conteiner
            document.getElementById('grid_conteiner')
                .setAttribute("style", "height:" + (winHeight - headerHeight - footerHeight) + "px");
        }

    };
</script>

关于javascript - 想要在浏览器窗口最小化或最大化时重置 RadGrid 高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40610452/

相关文章:

c#-4.0 - tableclient.RetryPolicy 对比 transient 故障处理

c# - MemberwiseClone 与新对象

asp.net - Json.Net 反序列化 - Web API 和可空日期

javascript - 如何访问 `$scope.search.value`?

javascript - 如何使用javascript访问JSON格式的数据

javascript - 是否可以在Golang中获取需要JS的网页?

c# - 使用 asp.net 验证器就足够了吗?

c# - 如何在服务器标签中使用强类型资源?

C# 上下文已经在跟踪实体、azure Active Directory 图形 api。添加群组成员

javascript - ng-repeat 隐藏重复项