[英]How to set scrollable content dinamically in ng zorro table?
I have a ng-zorro table and i would want the scroll bar to resize when i resize the browser window (say for example in a smaller device).我有一个 ng-zorro 表,我希望在调整浏览器 window 的大小时调整滚动条的大小(例如在较小的设备中)。 So that it will be dinamically changed based on the page size, how to do that?
这样它将根据页面大小进行动态更改,该怎么做?
Well, firstly you should provide more context to your question: for example you could provide a minimal reproducible example and some code so we can have more context to the question asked.好吧,首先你应该为你的问题提供更多的上下文:例如,你可以提供一个最小的可重现示例和一些代码,这样我们就可以对所提出的问题有更多的上下文。
But anyway i will try to answer your question:但无论如何我会尝试回答你的问题:
Here's what you can do:以下是您可以执行的操作:
nzScroll
that takes an object as argument.nzScroll
有一个属性,它以 object 作为参数。<nz-table [nzScroll]="{ y: 'calc(100vh - 276px)' }">
</nz-table>
What is that code doing?这段代码在做什么?
So since we want to scroll vertically (and not horizontally) we need to change the y axis ence the y:
in the code.因此,由于我们要垂直滚动(而不是水平滚动),我们需要在代码中更改 y 轴和
y:
:。
you can assign a pixel value to that y
but that will result your scrollbar to have a fixed height so resizing the window will not resize the scrollbar.您可以为该
y
分配一个像素值,但这将导致您的滚动条具有固定的高度,因此调整 window 的大小不会调整滚动条的大小。
what i did was calculate all the elements heights in my page so that i know how much height my table is taking.我所做的是计算页面中所有元素的高度,这样我就知道我的桌子占用了多少高度。 I did this when the table was empty using an extension for google chrome smart page ruler extension
当表格为空时,我使用 google chrome 智能页面标尺扩展的扩展来执行此操作
knowing the elements height in my page i could subtract that amount to the viewHeight
of my page.知道我页面中的元素高度,我可以将该数量减去我页面的
viewHeight
。
Therefore everytime you resize the window the scrollbar is going to resize because is calculating the difference between 100% of the viewHeight and the sum between all of your elements heights.因此,每次调整 window 的大小时,滚动条都会调整大小,因为正在计算 100% 的 viewHeight 与所有元素高度之间的总和之间的差异。
If you have any question about my answer i will happly answer, cheers!如果您对我的回答有任何疑问,我会很乐意回答,干杯!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.