0

I developed a simple code in Python Flet that consists of a DataTable added to a Row, inserted into a Column. These nested controls are added into a container with dimensions that don't allow to display all the table content. With the current settings (ft.Scroll.ALWAYS for the Column, and ft.Scroll.ADAPTIVE for the Row), the vertical scroll bar is shown but the horizontal scrollbar appears only when the table is moved down at its bottom. I would like to have both vertical and horizontal scrollbars always visible on the table. I tried to change the values of both scroll types but nothing changed.

import flet as ft

def main(page: ft.Page):
    column_items = [ft.DataColumn(ft.Text(f"Column {i+1}")) for i in range(36)]
    cell_items = [ft.DataCell(ft.Text(f"Cell {i+1}")) for i in range(len(column_items))]
    row_items = [ft.DataRow(cells=cell_items) for _ in range(50)]
    data_table = ft.DataTable(columns=column_items, rows=row_items)


    page.horizontal_alignment = ft.CrossAxisAlignment.CENTER
    page.vertical_alignment = ft.MainAxisAlignment.CENTER
    page.add(
        ft.Container(
            height=500,
            width=700,
            content=ft.Column(
                scroll=ft.ScrollMode.ALWAYS,
                controls=[
                    ft.Row(
                        scroll=ft.ScrollMode.ADAPTIVE,
                        controls=[data_table],
                    )
                ],
            ),            
        )        
    )    

ft.app(target=main)
2
  • maybe it will need to use other widget with scrollbars or add scrollbars as separate object and use events to control table. Scrolling controls and Theming | Flet Commented Mar 6 at 13:51
  • I already tried to modify scrollbar theming setting both thumb visibility and track visibility to True. Nothing has changed. Commented Mar 6 at 14:08

1 Answer 1

0

Currently, Flet doesn’t support this feature out of the box.
This has also been requested on the official GitHub issues.


Disclaimer: I’m the author of Flet-Extended-Interactive-Viewer.
I ran into the same limitation and created this extension, which adds two-dimensional scrollbars and some additional functionality.

Here’s how you can use it with your code:

import flet as ft
from flet_extended_interactive_viewer import FletExtendedInteractiveViewer

def main(page: ft.Page):
    column_items = [ft.DataColumn(ft.Text(f"Column {i+1}")) for i in range(36)]
    cell_items = [ft.DataCell(ft.Text(f"Cell {i+1}")) for i in range(len(column_items))]
    row_items = [ft.DataRow(cells=cell_items) for _ in range(50)]
    data_table = ft.DataTable(columns=column_items, rows=row_items)


    page.horizontal_alignment = ft.CrossAxisAlignment.CENTER
    page.vertical_alignment = ft.MainAxisAlignment.CENTER
    page.add(
        FletExtendedInteractiveViewer(
            height=500,
            width=700,
            content=ft.Column(
                scroll=ft.ScrollMode.ALWAYS,
                controls=[
                    ft.Row(
                        scroll=ft.ScrollMode.ADAPTIVE,
                        controls=[data_table],
                    )
                ],
            ),
            constrained=False,
        )
    )

ft.app(target=main)

With this setup, you have both vertical and horizontal scrollbars always visible.
Screenshot of the running app

By default, panning is enabled in the extension. If you only want scrolling via the scrollbars, you can disable it:

pan_enabled = False

This way, FletExtendedInteractiveViewer works like a nested row and column with scrollbars.

Note:
When developing a web application, Flet extensions currently do not work there, so you would need a different solution.

Sign up to request clarification or add additional context in comments.

4 Comments

Even with the disclosure, this post, at its current status, serves only to promote the linked page. Read How to not be a spammer. Also, don't just post a link. Attach a demo and explanation on how the link can resolve OP's problem.
Thanks for your feedback. I tried to implement the input, and I really appreciate it. It was never my intention to be a spammer; I just wanted to help other people who run into the same problem I have had.
Hi, Florian, I just pip install Flet-Extended-Interactive-Viewer, and I ran the demo script you provide here. what I got was the error message : "Unknown control: flet_extended_interactive_viewer" , I check the content type what put inside of page.add was flet_extended_interactive_viewer.flet_extended_interactive_viewer.FletExtendedInteractiveViewer. I am not sure why I cannot run your demo script successfully, do you have any idea for this error? Thank you for your kindly feedback in advance.
Hi @allenwei, this issue occurs because custom extensions in Flet are only registered during the build process. It’s currently not possible to use an extension directly after pip install without building the project at least once. To fix it, you need to install the extension and then run the build command once, for example: flet build macos -v (or the appropriate command for your platform). During this build, Flet registers all extensions so that they can be recognized as valid Flet controls. This limitation also applies to other extensions, such as the Flip Card extension.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.