Is it possible to have fixed headers when the table is inside a scrollable container?

Is it possible to have fixed headers when the table is inside a scrollable container?

dtuser1854dtuser1854 Posts: 11Questions: 3Answers: 0

I forked a jsfiddle at https://jsfiddle.net/0chkxs6g/ but I cannot be 100% sure if it's not working because I made an error or because fixed headers don't work within a scrollable container.

However if you go to https://datatables.net/extensions/responsive/examples/column-control/fixedHeader.html then inspect element and add max-height: 400px; overflow: auto; to #example_wrapper you can see that the fixed headers only act on the browser scroll, not on the container scroll.

Is it possible to make the fixed headers work on the container scroll?

Thanks!

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Hi,

    Sorry I missed this thread a few days ago. At the moment no, there is no support for FixedColumns in a scrolling container I'm sorry to say.

    Part of the issue is to know what elements to listen for the scroll event on - it might be that I have to provide an option for a selector to identify which elements to check for. The automatic part I suspect will be fraught with performance issues or edge cases.

    It is something I'd like to add, it just hasn't yet been prioritised over other things I'm afraid.

    Allan

  • dtuser1854dtuser1854 Posts: 11Questions: 3Answers: 0

    No need to apologize, I appreciate the response!

    Yes I imagine providing an option for which element (I think it can be a single element) as the container would be the way to go. Having not looked at the code, I would hope it might be as simple as making the default container the html element, letting it be overridden when needed, and changing the current code to act off that container. Of course knowing how code goes I'm sure it's not as simple as that :)

    Thanks!

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Its slightly more complicated than that since the scrolling container itself could be scrolling in the window - so there needs to be multiple listeners and each take account of the position of each. Imagine a scrolling container part partly visible and scrolling the container, not the window.

    There will be a lot of code reuse from what is already there, but there are implications that will need to be considered in more detail.

    If you or anyone else are up for it, I'd take a pull request that implements it, if you get to doing so before I can :)

    Allan

  • dtuser1854dtuser1854 Posts: 11Questions: 3Answers: 0
    edited August 2023

    Ah that makes sense - I was only thinking of my use case where I have a header and footer and a main content area that scrolls instead of of the browser scrolling. In that scenario it is simple because the scrolling container can't scroll in the window,

    I will definitely have a look at it, but my experience is in the backend, I only have a cursory knowledge of javascript.

    Thanks!

Sign In or Register to comment.