From 798b60ae3c5a359114d4c90732803737356b1610 Mon Sep 17 00:00:00 2001 From: lukas Date: Thu, 6 Nov 2025 12:52:15 +0100 Subject: [PATCH] feat: optional collapsible nested table --- docs/components/table.md | 5 +-- .../templates/unfold/components/table.html | 36 ++++++++++--------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/docs/components/table.md b/docs/components/table.md index 1e0abcdb4..df728a003 100644 --- a/docs/components/table.md +++ b/docs/components/table.md @@ -19,6 +19,7 @@ The table component requires a dictionary with the following structure: def dashboard_callback(request): return { "table_data": { + "collapsible": True, "headers": ["col 1", "col 2"], "rows": [ ["a", "b"], @@ -50,8 +51,8 @@ data = { { "cols": ["c", "d"], # Cols in row "table": { - "headers": ["col2", "col3"] - "rows" [ + "headers": ["col2", "col3"], + "rows": [ ["g", "h"] ] } diff --git a/src/unfold/templates/unfold/components/table.html b/src/unfold/templates/unfold/components/table.html index f2a99fd68..297df00dd 100644 --- a/src/unfold/templates/unfold/components/table.html +++ b/src/unfold/templates/unfold/components/table.html @@ -13,10 +13,6 @@

- {% if table|has_nested_tables %} - - {% endif %} - {% for header in table.headers %} {{ header|capfirst }} @@ -30,32 +26,40 @@

- {% if row.table.rows %} - - - expand_more - - - {% endif %} - {% for cell in row.cols|default:row %} - {{ cell }} + {% if row.table.rows|length > 0 %} +
+ {% if forloop.first and row.table.rows|length > 0 and row.table.collapsible %} +
+ expand_more +
+ {% endif %} + +
+ {{ cell }} +
+
+ {% else %} + {{ cell }} + {% endif %} {% endfor %} {% if "table" in row %} - + - + {% if table.collapsible %} + + {% endif %} {% if row.table.headers %} {% for header in row.table.headers %} - {% endfor %}