I have a normal prime Ng table which is scrollable vertically. However, if the screen size is too small, I end up with the normal page scroll aswell as the table scroll.
Is there a way around this? To make the table the size of whatever the screen is, with an infinite scroll. So basically the table scroll would turn into the main page scroll at the side of the page? Instead of having two?
So basically the table scroll would turn into the main page scroll at the side of the page? Instead of having two?
Explanation
By default p-table stretches downwards infinitely, unless you limit it's height, in which case it will have a vertical scroll if there's more data than can fit within the height you set.
Moreover, if all your elements together on the page (including the table), don't fit the current view, page will also get it's own scroll.
E.g. I have a menu on top of the page, under it a card with other things, then a table toolbar, then the table, that's a lot of elements and they won't fit within the view, so page will get it's own scroll. Meanwhile your table has scrollHeight of 600px, yet you have data for 900px, it will get it's own scroll too. Boom 2 scrolls.
Fix You can fix it in a few different ways but it all comes down to the desired behavior/look of your page... when I had this prob I just removed height restrictions and let table expand downwards infinitely, it wasn't a problem because: 1- table was the last element of the page from top to bottom; 2- I had paginator to limit size regardless. So I ended up with only the page scroll.
Related
I am working on building sticky sidebar behavior that will run alongside a vertical feed which is very similar to a facebook feed on desktop web. position: sticky works well for the easy use case where the sidebar is shorter than the height of the viewport. However if your sidebar is larger than the viewport the sidebar needs to have some scrolling mechanism so you can see the bottom of the sidebar as you scroll down the feed.
I am trying to recreate the facebook sidebar sticky scroll here.
The best way to understand the desired behavior is to test out your facebook feed and shrink your screen height so that your viewport is smaller than your sidebar height. I'll try to summarize here:
When your viewport is taller than your sidebar (simple case)
The sidebar behaves exactly as you'd expect with position: sticky. The sidebar stays in the same place and follows as you scroll down and up.
When your viewport is smaller than your sidebar
When you scroll down initially the sidebar scrolls with the feed (they appear fixed together)
When you get to the bottom of your sidebar, it then locks at the bottom and as you scroll down more, the sidebar now appears sticky with the bottom fixed
When you now scroll back up, the sidebar once again appears attached to your main feed, and scrolls up with the main feed. Once you hit the top of the sidebar it's then sticky with the top fixed.
So between those two states (top fixed when scrolling up, bottom fixed when scrolling down), the sidebar scrolls in unison with the main feed.
It's a very nice scrolling experience but very hard to recreate.
I have accomplished the states listed in steps 1-3 above by applying position sticky with a top position, and when you scroll down, using scroll events and some viewport/sidebar height calculations to determine the height difference and adjusting the top css value so it locks when the bottom is lined up with the screen (essentially initialTop - (sidebarHeight - viewportHeight). I cannot figure out steps 4, and 5. The best I could do was transition between the two top values depending on your scroll direction but it's a very bad UX.
I have a sandbox example of a layout here: https://codesandbox.io/s/fragrant-microservice-89b7z?fontsize=14&hidenavigation=1&theme=dark
There's a basic layout with 2 columns (left sidebar and main feed). And there's a react component called StickyScroll which wraps around the column and has all the logic to update the top value. This may be a completely wrong start to a good solution, but any help is greatly appreciated.
I was interested in this as well, so I spent some time studying how fb does it.
It's very clever, my hat off to whichever fb dev originally implemented this.
You have to set the top / bottom css properties on the sticky depending on the direction of scroll, and to keep things from jumping around, you also have to calculate the height of an the element above the sticky, based on scrollTop.
Here is a rough example, which demonstrates the logic in action
I try to make a mock up by your sandbox code based on facebook redesign 2020.
hope you find the answer here. I like this approach because it's not very complex. More precisely, I use the css solution when I have to create a component similar to the Facebook sidebar.So i'm not using your StickyScroll component. Hope you find something.
Codesandbox Independent Scroll
I have a website with a very big header that will go out of screen when scrolling (I want this), then I have two columns. I'd like the left column (it's a section at the moment) to remain visible all the time while the right one scrolls down.
position: fixed; is not what I'm looking for, as I would like the left column to scroll until it reaches the top of the screen, and then stay there.
I know this can be done with javascript, but is it possible to do this just using css?
My page has a fixed header, a fixed right sidebar, and an HTML table with each column having a set width (so that the table stays left of the sidebar). The table scrolls vertically, while the rest of the page remains fixed.
Each row has an expand button, which shows another row under it, with a bunch of images. This row may get very long, so the overflow needs to be hidden behind the side bar (already doing that). However, since I changed to the fixed sidebar paradigm, I am unable to scroll the row to the right without moving the whole table with it.
I will try to create a JSFiddle, but my app is an Ember/Bootstrap app, so may take a while to reconstruct in JSFiddle format. If you know the answer off-hand, please let me know.
I'm new to HTML and CSS. For some reason my page has empty space on the right side and lets the user side scroll. I know I can hide the scroll bar with overflow-x but that still lets them scroll. How do I get rid of the extra space/why is it there? There's more of it on the index page than on the projects page.
zarwanhashem.com
The <div> that contains the text 'Hello...' has a default width of 100% of the page. But you have set it's position to relative and pushed it 30em to the left - which is pushing it off the right side of the page, causing the scroll.
There are lots of ways you could fix it and I'm not going to do a full run down.
A quick fix would be to add display: inline-block to the css for that div. This will stop it taking a 100% width.
I have a number of width: 100%; divisions as part of my HTML page, however when I zoom in on the page or view on a low resolutions such that some of the content goes past the horizontal limit of the screen (and hence a horizontal scrollbar appears), I find that scrolling to the right results in my 100% width division cutting off.
This effect is demonstrated below:
The same happens with this web page, here on Stack Overflow. If you zoom in using FF5.0, the footer and headers are "cut" when you scroll right. This is because the content div has to overflow on the right.
I think you want to avoid having overflows on the side (it's not aesthetically pleasing, and it's harder to navigate through the page).
A solution could be to not have divs that have a minimal width (eg 960px for the div#content of this web page), but rather are variable (50%). If you zoom in, width=50% will stay 50%, it will not overflow.
PS: but it might be better to have some JavaScript code to do the zoom for you, so that you can more or less control what the end-user sees when they click on the zoom button that you'd provide, on the page.