简体   繁体   English

银格粘header

[英]Ag-grid sticky header

So my ag-grid resize itself because my row height is also dynamic.所以我的 ag-grid 会自行调整大小,因为我的行高也是动态的。 So for height I am using [style.height.px]="beta" and this.beta = document.getElementsByClassName('ag-full-width-container')["0"].offsetHeight + 139 And the pagination is set to 100 .所以对于高度我使用[style.height.px]="beta"this.beta = document.getElementsByClassName('ag-full-width-container')["0"].offsetHeight + 139并且设置了pagination100

I cannot use autoHeight because I have more than 10k rows.我不能使用autoHeight因为我有超过 10k 行。 So I want my header to be sticky.所以我希望我的 header 具有粘性。 I have some content before ag-grid in DOM.我在 DOM 中的 ag-grid 之前有一些内容。 As I scroll I want my ag-grid header to stick to the top.当我滚动时,我希望我的 ag-grid header 贴在顶部。 I am using top:0;position:sticky;z-index:1000 It's working for every div tag except ag-gird 's div tag.我正在使用top:0;position:sticky;z-index:1000它适用于除ag-girddiv标签之外的每个div标签。 So is there a way to have a sticky header in ag-grid?那么有没有办法在 ag-grid 中有一个粘性 header ?

On onGridViewChanged() function I implemented the following logic.onGridViewChanged() function 我实现了以下逻辑。 So in this logic the HTML above ag-gird in DOM should be consider for top because ag-grid header top was 0 for me.所以在这个逻辑中,DOM 中的ag-gird HTML上方的 HTML 应该被考虑为top ,因为 ag-grid header top对我来说是0 And then add some value according to your requirement (calibration).然后根据您的要求添加一些值(校准)。 Then for the row body add some margin (calibration).然后为行体添加一些margin (校准)。

    onGridViewChanged() {
        let header = $('.ag-header')
        let headerPos = $('.btn-row').position().top + 50
        $(window).on("scroll", function () {
            if ($(window).scrollTop() > headerPos) {
                header.css("position", "fixed").css("top", 0).css("z-index", "99");
                $('.ag-body-viewport.ag-layout-normal').css("margin-top", "88px");
            }
            else {
                header.css("position", "static");
                $('.ag-body-viewport.ag-layout-normal').css("margin-top", "0px");
            }
        });
    }

I would suggest eliminating the scrollbars that are outside of the grid, and make the grid fit within the window.我建议消除网格外部的滚动条,并使网格适合 window。 You can use flexbox to do that.您可以使用 flexbox 来做到这一点。 You need to make sure the parent elements are using display: flex and have 100% height.您需要确保父元素使用display: flex并具有 100% 的高度。 And then set the grid to be flex-grow: 1 .然后将网格设置为flex-grow: 1

On the parent element(s):在父元素上:

height: 100%;
display: flex;
flex-direction: column;

On the grid:在网格上:

flex-grow: 1;

https://stackblitz.com/edit/angular-ag-grid-full-height?embed=1&file=src/app/app.component.html https://stackblitz.com/edit/angular-ag-grid-full-height?embed=1&file=src/app/app.component.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM