lorenzofox3 / lrStickyHeader

make table headers sticky
MIT License
174 stars 27 forks source link

lrStickyHeader not working for table inside a container with overflow:auto and fix height #13

Closed mathiasconradt closed 7 years ago

mathiasconradt commented 8 years ago

The lrStickyHeader library does not work when the table is inside a container with a fixed height and overflow:auto; where the table fills the entire height of the container height (dynamically).

See your adjusted example: https://jsfiddle.net/361vw6c3/

I would expect it to work in the same way as the CSS approach, where you can have something fix above the table. https://plnkr.co/edit/3oyuGZgPmLlaFSly41au?p=preview

gvangool commented 8 years ago

@mathiasconradt my fix for this has just been merged. Could you try it?

mathiasconradt commented 7 years ago

@gvangool It's still not working for me. I created a Codepen with the latest js from the master.

Edit view: http://codepen.io/mathiasconradt/pen/mRVNbr/ Debug view: http://codepen.io/mathiasconradt/debug/mRVNbr

The container with overflow and fixed height is in the html in line 15. If you remove the style there, the fixed header works fine, with that style active, the sticky header does not work. If it works for you, could you create a Codepen fork and let me know the link.

mathiasconradt commented 7 years ago

@gvangool I found something else with another Codepen: what's also interesting is that even without an overflow div and no fixed height, the sticky header does not work inside the codepen edit view:

http://codepen.io/mathiasconradt/pen/KaVOMB/

while it works when opening the same codepen in it's debug or full view:

http://s.codepen.io/mathiasconradt/debug/KaVOMB/dXkqBOGPeLmM

gvangool commented 7 years ago

@mathiasconradt you need to specify the ancestor element (with the fixed height):

lrStickyHeader(tables[0], {parent: document.getElementById("parent1")});

That's also the reason why it doesn't work in the codepen edit view. By default it will use the window scrolling which never triggers.

Edit: fixed codepen can be found at http://codepen.io/gvangool/pen/qRNZRR

mathiasconradt commented 7 years ago

@gvangool Ok, I see. Right, it's working now with that.