pythonnicegui

NiceGUI Table Dynamic Title


I'm using NiceGUI and trying to create a table with a dynamic title. I want to be able to change the title of the table dynamically, just like I can update the columns and rows properties.

# Create the table with an initial title
existing_table_route = ui.table(
    columns=[], 
    rows=[], 
    row_key='Route/Variant', 
    title="Existing - Rate / SKU - Routewise"
).classes('my-table-style-1').style('text-align:right;')

# Function to update the table title dynamically
def update_table_title(new_title):
    existing_table_route.title = new_title  # Update the title
    existing_table_route.update()  # Refresh the table to reflect the title change

# Button to dynamically change the title
ui.button('Change Title', on_click=lambda: update_table_title('New Dynamic Table Title'))

However, when I attempt to change the title dynamically using the update_table_title() function, it does not seem to update the table's title as expected.

Steps I tried:

Expected behavior:

Questions:

Any help or insights would be greatly appreciated!

-


Solution

  • There is no title property in ui.table, that's why nothing happens when you assign a value to it.

    Instead you can update the "title" prop like this:

    ui.button('Change Title',
              on_click=lambda: existing_table_route.props('title="New Dynamic Table Title"'))