# Make a table auto scrollable

**URL:** <https://discuss.streamlit.io/t/make-a-table-auto-scrollable/55443>\
**Category:** Using Streamlit\
**Created:** [November 14, 2023, 9:50pm UTC](https://discuss.streamlit.io/t/make-a-table-auto-scrollable/55443 "2023-11-14T21:50:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexandre\_Choske](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/alexandre_choske/32/33456_2.png) [@Alexandre\_Choske](https://discuss.streamlit.io/u/Alexandre_Choske)\
**Post date:** [November 14, 2023, 9:50pm UTC](https://discuss.streamlit.io/t/make-a-table-auto-scrollable/55443/1 "2023-11-14T21:50:12Z")

</div>

Hi guys, I’m having a hard mission here.

I’m trying to make this table on my dashboard auto-scrollable, and when it gets to the end of it, make the scroll start again from the beginning, like a loop of scrolling.

I’ve already tried several things, but with no success 😕, such as injecting JS into the HTML container, but with zero results.

Maybe you have a suggestion. Thanks.

```auto
def convert_df(input_df):
    df_html = input_df.to_html(index=False, escape=False, formatters=dict(MODAL_IMG=image_formatter, CANAL=image_formatter))
    
    html_with_container = f"""
            <div id="table-container" style="height: 400px; overflow-y: auto;">
        {df_html}
    </div>
    <script>
        var container = document.getElementById("table-container");
        setInterval(function() {{container.scrollBy(0, 1)}}
        , 100);
    </script>
    """
    return html_with_container

html = convert_df(df)
st.markdown(html, unsafe_allow_html=True)

```

---

<div class="post-metadata">

**Author:** ![dataprofessor](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/dataprofessor/32/44163_2.png) [@dataprofessor](https://discuss.streamlit.io/u/dataprofessor)\
**Post date:** [November 15, 2023, 2:02am UTC](https://discuss.streamlit.io/t/make-a-table-auto-scrollable/55443/2 "2023-11-15T02:02:08Z")

</div>

Hi @Alexandre_Choske

Here’s a post on StackOverflow with a solution implemented in jQuery to automatic scroll to bottom and back up once reaching the bottom as you had intended:

> <https://stackoverflow.com/questions/36873753/scroll-element-up-and-down-automatically>

Hope this helps!

---

<div class="post-metadata">

**Author:** ![Alexandre\_Choske](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/alexandre_choske/32/33456_2.png) [@Alexandre\_Choske](https://discuss.streamlit.io/u/Alexandre_Choske)\
**Post date:** [November 15, 2023, 1:13pm UTC](https://discuss.streamlit.io/t/make-a-table-auto-scrollable/55443/3 "2023-11-15T13:13:52Z")

</div>

Hi @dataprofessor, I tried your solution but also no results.

The styling works, because when I hover the mouse the table border is red.  
But the animation (jQuery) is not working.

```auto
def convert_df(input_df):
    df_html = input_df.to_html(index=False, escape=False, formatters=dict(MODAL_IMG=image_formatter, CANAL=image_formatter))
    
    html_with_container = f'''
        <html>
        <head>
            <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
            <style>
                .table-container {{
                    height: 400px;
                    width: 100%;
                    overflow-y: auto;
                    border: 2px solid #444;
                }}
                .table-container:hover {{ border-color: red; }}
                table {{ width: 100%; }}
                td {{ padding: 24px; background: #eee; }}
            </style>
        </head>
        <body>
            <div class="table-container" id="table-container">
                {df_html}
            </div>
            <script>
                var $container = $("#table-container");
                function anim() {{
                    var st = $container.scrollTop();
                    var sb = $container.prop("scrollHeight") - $container.innerHeight();
                    $container.animate({{scrollTop: st < sb / 2 ? sb : 0}}, 4000, anim);
                }}
                function stop() {{
                    $container.stop();
                }}
                anim();
                $container.hover(stop, anim);
            </script>
        </body>
        </html>
        '''
    return html_with_container

html = convert_df(df)
st.markdown(html, unsafe_allow_html=True)

```

 ![image](https://global.discourse-cdn.com/streamlit/original/3X/1/b/1bd4bd11388f775446ab38590bf5324dfd4040d5.png)

☹

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/streamlit/original/3X/c/f/cf4c2ee0d938358f82448c5fe4b9c3c91d7ce19c.svg) [@system](https://discuss.streamlit.io/u/system)\
**Post date:** [May 13, 2024, 1:14pm UTC](https://discuss.streamlit.io/t/make-a-table-auto-scrollable/55443/4 "2024-05-13T13:14:40Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
