Search code examples
pythontaipy

How to highlight a selected row of a table in Taipy?


I am working with Taipy GUI to create a web app. So far I am able to generate a table and keep track of a selected row of the table. However, I want to show the user which row they selected by highlighting it on the frontend. I couldn't find how to do this in the docs. Can someone help me?

I checked the docs but didn't find anything that helped me.


Solution

  • You can use the selected property to get a visual feedback on your selection.

    See below a simple example:

    from taipy.gui import Gui 
    
    data = {"Name":["A","B","C"], "Age":[1,2,3]}
    
    selected = []
    
    page = "<|{data}|table|on_action=on_selection|selected={selected}|>"
    
        
    def on_selection(state, var_name, action, payload):
        idx = payload['index']
        state.selected = [int(idx)]
        ...
    
    
    Gui(page).run()
    

    enter image description here