Skip to content

Commit 2760cb8

Browse files
committed
Add table demo
1 parent d0a32c8 commit 2760cb8

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

chartlets.py/demo/my_extension/my_panel_4.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
from chartlets import Component, Input, State, Output
1+
from chartlets import Component, Input, Output
22
from chartlets.components import Box, Slider, Typography
33

44
from server.context import Context
55
from server.panel import Panel
66

7+
from chartlets.components.charts.table import Table
78

89
panel = Panel(__name__, title="Panel D")
910

@@ -36,6 +37,25 @@ def render_panel(
3637

3738
info_text = Typography(id="info_text", children=["Move the slider."])
3839

40+
columns = [
41+
{"field": "id", "headerName": "ID"},
42+
{"field": "firstName", "headerName": "First Name", "width": 100},
43+
{"field": "lastName", "headerName": "Last Name"},
44+
{"field": "age", "headerName": "Age"},
45+
]
46+
47+
rows = [
48+
{"id": 1, "firstName": "John", "lastName": "Doe", "age": 30},
49+
{"id": 2, "firstName": "Jane", "lastName": "Smith", "age": 25},
50+
{"id": 3, "firstName": "Peter", "lastName": "Jones", "age": 40},
51+
]
52+
53+
table = Table(id="table", rows=rows, columns=columns, checkboxSelection=True)
54+
55+
table_text = Typography(
56+
id="table_text", children=["Click on any row in " "the table."]
57+
)
58+
3959
return Box(
4060
style={
4161
"display": "flex",
@@ -44,15 +64,17 @@ def render_panel(
4464
"height": "100%",
4565
"gap": "6px",
4666
},
47-
children=[slider, info_text],
67+
children=[slider, info_text, table, table_text],
4868
)
4969

5070

5171
# noinspection PyUnusedLocal
52-
@panel.callback(Input("slider"), Output("info_text", "children"))
53-
def update_info_text(
54-
ctx: Context,
55-
slider: int,
56-
) -> list[str]:
72+
@panel.callback(
73+
Input("slider"),
74+
Input("table"),
75+
Output("info_text", "children"),
76+
Output("table_text", "children"),
77+
)
78+
def update_info_text(ctx: Context, slider: int, table) -> tuple[str, str]:
5779
slider = slider or 0
58-
return [f"The value is {slider}."]
80+
return f"The value is {slider}.", f"The selected row is {table}."

0 commit comments

Comments
 (0)