DataTables / FixedHeader

Fix the header, footer, left or right columns of a table in place, to always show them when scrolling
http://www.datatables.net/
Other
75 stars 83 forks source link

Add event handlers to resize and position headers #58

Closed ghost closed 9 years ago

ghost commented 9 years ago

init.dt allows header column sizes to respond to size changes due to ajax data

With multiple DataTables on a page, draw.dt allows headers to reposition after ajax data has loaded (fixes vertical positioning before scrolling) and after searching changes the number of displayed rows (occurs after scroll has fired at least once)

The issues can be seen in this jsFiddle. Make sure not to scroll to see the second tables header over the first table. Then scroll, and search for something that isn't in the first table and you will see the second tables header is now out of position.

This jsFiddle shows the result of this pull request. Not perfect, but a step in the right direction.

This seems to address issue #49.

DataTables commented 9 years ago

Hi

Thanks for the PR. There shouldn't actually be any need for the init event I wouldn't have thought - the draw should handle that as well.

I've just tried your example with the 3.0.0-dev version of FixedHeader (found in the 3 branch on this repo) and this seems to work nicely (after it allowed me to find some issues with tables that don't have footer elements!). Could you try v3 and let me know what you think?

ghost commented 9 years ago

v3 is working for all of my use cases, I didn't realize it was that far along. I'll be using it instead. Thanks!

Actually it appears that during the first draw event, the column widths have not yet responded to the data in the table (subsequent draw events pick up the right size however). Drop a breakpoint in draw on line 278 to see it in action. If I delay to the next tick, it picks up the new widths though.

I wasn't sure about recloning the headers in every draw event - at least for my use cases, just doing it during init seemed to work fine. I'm more than happy to amend the commit and reclone in draw as well if you still want to merge this.

DataTables commented 9 years ago

This is sort of expected with Ajax requested data - DataTables will resize the columns after the Ajax data has loaded (which occurs with the second draw). However, I'll look into if this can be improved. Thanks for the pointer.

ghost commented 9 years ago

3.0.0 has been released and doesn't have these issues. :beer: