Cell_Class_Name question #2778
-
|
Hello Taipy team, I'm currently encountering a problem with the Below is a simple example I've attached (one To briefly explain the problem I'm trying to solve: In I added My expectation is that both tables should display the same result (both should have CSS applied), but the table with Cell_Class_Name_Test.py: from taipy.gui import Gui, navigate ===== 初始狀態變數 =====tables = [] def on_table_action(state, var_name, payload): def cell_class_UM1(state, value, row, col, row_index): with tgb.Page() as root_page: pages = { Gui(pages=pages, css_file="style.css").run( style.css: .Setting_Page_Button{ |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Beta Was this translation helpful? Give feedback.
-
|
Hi @asdf77449212-art . I think I see the issue. Here is a shorter, working example: import pandas as pd
import taipy.gui.builder as tgb
from taipy.gui import Gui, State
df = pd.DataFrame(
{
"id": [1, 2, 3, 4, 5, 6, 7, 8],
"status": ["primary", "secondary", "error", "warning", "success", "primary", "secondary", "error"],
}
)
def cell_class_status(state: State, value, index, row, column_name):
if value == "primary":
return "bg-primary"
elif value == "secondary":
return "bg-secondary"
elif value == "error":
return "bg-error"
elif value == "warning":
return "bg-warning"
elif value == "success":
return "bg-success"
with tgb.Page() as page:
tgb.table(data="{df}", cell_class_name__status="{cell_class_status}")
table_properties = {"cell_class_name[status]": "{cell_class_status}"} # Note the dictionary key here
tgb.table(data="{df}", properties="{table_properties}")
Gui(page).run()SolutionWhen using a Taipy indexed property as a # Wrong ❌
table_properties = {"cell_class_name__status": "{cell_class_status}"}
# Correct ✅
table_properties = {"cell_class_name[status]": "{cell_class_status}"}Additional notesBy the way, passing indexed properties like this is also useful when you have column names that are not valid Python identifiers. For example, if you have a column in your dataframe called # You can't do ❌
tgb.table(..., cell_class_name__Current Status="{cell_class_status}")
# because you can't have whitespace in a parameter name
# You should do ✅
table_properties = {"cell_class_name[Current Status]": "{cell_class_status}"}
tgb.table(..., properties="{table_properties}")Let me know if this addresses your issue. |
Beta Was this translation helpful? Give feedback.

Hi @asdf77449212-art .
I think I see the issue. Here is a shorter, working example: