El taller de componentes: los 100 componentes de Reflex
·
Resumen del curso
Diseño
·
Box
·
Flex
·
Stack
·
Grid
·
Container
·
Section
·
Center
·
Spacer
·
Separator
·
Card
·
Inset
·
Aspect Ratio
·
Fragment
Tipografía
·
Text
·
Heading
·
Link
·
Code
·
Markdown
·
Blockquote
·
Quote
·
Strong
·
Em
·
Kbd
Formularios
·
Button
·
Input
·
Text Area
·
Checkbox
·
Switch
·
Radio Group
·
Select
·
Slider
·
Form
·
Upload
Visualización de datos
·
Badge
·
Avatar
·
Icon
·
Callout
·
List
·
Data List
·
Code Block
·
Progress
·
Spinner
·
Scroll Area
·
Moment
Mostrar y ocultar
·
Tabs
·
Accordion
·
Segmented Control
Superposiciones
·
Tooltip
·
Popover
·
Hover Card
·
Dialog
·
Alert Dialog
·
Drawer
·
Dropdown Menu
·
Context Menu
·
Toast
Renderizado dinámico
·
Cond
·
Match
·
Foreach
·
Auto Scroll
Multimedia
·
Image
·
Audio
·
Video
Tablas y cuadrículas de datos
·
Table
·
Data Table
·
Data Editor
Gráficos
·
Area Chart
·
Bar Chart
·
Line Chart
·
Composed Chart
·
Pie Chart
·
Radar Chart
·
Radial Bar Chart
·
Scatter Chart
·
Funnel Chart
·
Treemap
·
Sankey Chart
·
Error Bar
Piezas de gráficos
·
Axis
·
Cartesian Grid
·
Chart Tooltip
·
Legend
·
Label
·
Reference
·
Brush
Otras bibliotecas de gráficos
·
Plotly
·
Pyplot
Elementos HTML
·
HTML
·
HTML Text
·
HTML Layout
·
HTML Forms
·
HTML Media
·
HTML Tables
·
SVG
Otras herramientas
·
Theme
·
Skeleton
·
Clipboard
·
Html Embed
·
Script
·
Memo
rx.el.tablerx.el.captionrx.el.colgrouprx.el.colrx.el.theadrx.el.tbodyrx.el.tfootrx.el.trrx.el.thrx.el.tdDocumentación oficial
Pedido del taller
El tique de una cafetería como tabla: título, fila de cabecera con artículo · cantidad · precio y fila de pie con el total, todo en una tabla HTML pura.
Son los elementos de tabla HTML para mostrar datos en filas y columnas. Dentro del tbody de una table van las filas tr, y dentro de cada fila, celdas de cabecera th y celdas normales td.
No tienen estilo, así que los bordes y el relleno los pones tú. Si necesitas una tabla con aspecto Radix, usa rx.table; para una tabla con ordenación y búsqueda, rx.data_table.
| Name | Role |
|---|---|
| Ada | Engineer |
| Linus | Maintainer |
rx.el.table(
rx.el.tbody(
rx.el.tr(rx.el.th("Name"), rx.el.th("Role")),
rx.el.tr(rx.el.td("Ada"), rx.el.td("Engineer")),
rx.el.tr(rx.el.td("Linus"), rx.el.td("Maintainer")),
),
)El preflight de este sitio junta las celdas de la tabla (border_collapse="collapse"). Si lo cambias a separate, cada celda tiene su propio borde separado.
Prueba las propiedades
| Item | Qty |
|---|---|
| Apples | 3 |
| Pears | 12 |
caption
caption_side
align
collapse
rx.el.table(
rx.el.caption("Fruit stock", caption_side="top", padding="4px", font_weight="600"),
rx.el.thead(
rx.el.tr(
rx.el.th("Item", border="1px solid gray", padding="6px"),
rx.el.th("Qty", border="1px solid gray", padding="6px"),
),
),
rx.el.tbody(
rx.el.tr(
rx.el.td("Apples", border="1px solid gray", padding="6px"),
rx.el.td("3", align="right", border="1px solid gray", padding="6px"),
),
rx.el.tr(
rx.el.td("Pears", border="1px solid gray", padding="6px"),
rx.el.td("12", align="right", border="1px solid gray", padding="6px"),
),
),
border_collapse="collapse",
border_spacing="4px",
width="260px",
)| Propiedad | Valores | Por defecto | Uso |
|---|---|---|---|
col_span (td, th) | Entero | 1 | Número de celdas que se unen en horizontal |
row_span (td, th) | Entero | 1 | Número de celdas que se unen en vertical |
scope (th) | "col" "row" "colgroup" "rowgroup" | Ninguno | Dirección de la que se encarga esta cabecera |
headers (td, th) | id de los th | Ninguno | Indica directamente las cabeceras de esta celda |
align (td, th) | "left" "center" "right" "justify" "char" | Izquierda | Alineación en la celda (atributo antiguo; también vale el CSS text_align) |
span (col, colgroup) | Entero | 1 | Número de columnas que abarca un col |
align summary (table) | Cadena | Ninguno | Atributos antiguos, obsoletos en HTML5. Alineación con CSS, descripción con caption |
thead·tbody·tfoot dividen las filas en cabecera, cuerpo y pie. Las filas siempre van en uno de estos tres.
Si pones un tr directamente bajo table, el navegador inserta a escondidas un tbody, y la estructura puede no coincidir con la que conoce React.
caption es el título de la tabla y debe ser el primer hijo de table. El scope de th indica si esa cabecera corresponde a una columna ("col") o a una fila ("row").
| Month | Visitors |
|---|---|
| Jan | 1,200 |
| Feb | 1,450 |
| Total | 2,650 |
rx.el.table(
rx.el.caption("Monthly visitors", padding="4px", font_weight="600"),
rx.el.thead(
rx.el.tr(rx.el.th("Month", scope="col"), rx.el.th("Visitors", scope="col")),
background=rx.color("indigo", 3),
),
rx.el.tbody(
rx.el.tr(rx.el.th("Jan", scope="row"), rx.el.td("1,200")),
rx.el.tr(rx.el.th("Feb", scope="row"), rx.el.td("1,450")),
),
rx.el.tfoot(
rx.el.tr(rx.el.th("Total", scope="row"), rx.el.td("2,650", font_weight="bold")),
border_top="2px solid gray",
),
width="280px",
text_align="left",
)col_span=2 ocupa la celda de la derecha, y row_span=2 ocupa una celda de la fila de abajo. En el hueco ocupado no se pone td.
En el horario de abajo, la tercera fila tiene una celda menos.
| Mon | Tue | Wed | |
|---|---|---|---|
| 9 am | Workshop | Free | |
| 10 am | Lunch prep | Review | Free |
| 11 am | Free | Demo | |
rx.el.table(
rx.el.thead(rx.el.tr(rx.el.th(""), rx.el.th("Mon"), rx.el.th("Tue"), rx.el.th("Wed"))),
rx.el.tbody(
rx.el.tr(rx.el.th("9 am"), rx.el.td("Workshop", col_span=2, background=rx.color("indigo", 4)), rx.el.td("Free")),
rx.el.tr(rx.el.th("10 am"), rx.el.td("Lunch prep", row_span=2, background=rx.color("amber", 4)), rx.el.td("Review"), rx.el.td("Free")),
rx.el.tr(rx.el.th("11 am"), rx.el.td("Free"), rx.el.td("Demo")),
),
border="1px solid gray",
text_align="center",
width="340px",
)Cada col dentro de colgroup corresponde a una columna, y con span=2, a dos. Se usa para dar color de fondo o ancho a una columna entera.
El CSS que admite col se limita más o menos a background, width, border y visibility.
| Plan | Price | Seats |
|---|---|---|
| Starter | $0 | 1 |
| Team | $20 | 10 |
rx.el.table(
rx.el.colgroup(rx.el.col(), rx.el.col(span=2)),
rx.el.thead(rx.el.tr(rx.el.th("Plan"), rx.el.th("Price"), rx.el.th("Seats"))),
rx.el.tbody(
rx.el.tr(rx.el.td("Starter"), rx.el.td("$0"), rx.el.td("1")),
rx.el.tr(rx.el.td("Team"), rx.el.td("$20"), rx.el.td("10")),
),
width="300px",
text_align="left",
# style the columns from the table: Reflex puts a <style> tag next to a styled
# element, and the browser moves a <style> found inside <colgroup> out of it
style={
"& col:first-child": {"background": rx.color("gray", 3)},
"& col:last-child": {"background": rx.color("teal", 3)},
},
)En tablas complejas, se da un id a los th y se escribe ese id en el headers de los td para asociarlos. En pantalla se ve igual, pero los lectores de pantalla leen algo como "Price, $2".
| Fruit | Price |
|---|---|
| Kiwi | $2 |
rx.el.table(
rx.el.tbody(
rx.el.tr(rx.el.th("Fruit", id="htmltable_fruit"), rx.el.th("Price", id="htmltable_price")),
rx.el.tr(rx.el.td("Kiwi", headers="htmltable_fruit"), rx.el.td("$2", headers="htmltable_price")),
),
width="200px",
text_align="left",
)Si las filas salen de una lista del State, los tr se crean con rx.foreach. La ordenación se hace en una variable calculada, y la tabla dibuja el resultado tal cual.
| Name | Score |
|---|---|
| Jun | 95 |
| Mina | 88 |
| Sora | 72 |
class HtmlTableScoreState(rx.State):
rows: list[dict[str, str]] = [
{"name": "Mina", "score": "88"},
{"name": "Jun", "score": "95"},
{"name": "Sora", "score": "72"},
]
descending: bool = True
@rx.event
def flip_order(self):
self.descending = not self.descending
@rx.var
def sorted_rows(self) -> list[dict[str, str]]:
return sorted(self.rows, key=lambda r: int(r["score"]), reverse=self.descending)
rx.el.div(
rx.el.button(
rx.cond(HtmlTableScoreState.descending, "High to low", "Low to high"),
on_click=HtmlTableScoreState.flip_order,
padding="4px 12px",
border="1px solid gray",
border_radius="6px",
margin_bottom="8px",
),
rx.el.table(
rx.el.thead(rx.el.tr(rx.el.th("Name"), rx.el.th("Score"))),
rx.el.tbody(
rx.foreach(
HtmlTableScoreState.sorted_rows,
lambda row: rx.el.tr(rx.el.td(row["name"]), rx.el.td(row["score"], align="right")),
),
),
width="220px",
text_align="left",
),
)caption es el número de tique, thead la fila de cabecera y tfoot el total. La cabecera del total ocupa dos columnas con col_span=2, y las columnas numéricas se igualan de ancho con colgroup.
| Item | Qty | Price |
|---|---|---|
| Latte | 2 | $9.00 |
| Bagel | 1 | $3.50 |
| Total | $12.50 | |
rx.el.table(
rx.el.caption("Receipt #1024", padding="6px", font_weight="bold"),
rx.el.colgroup(rx.el.col(), rx.el.col(span=2)),
rx.el.thead(
rx.el.tr(rx.el.th("Item", scope="col"), rx.el.th("Qty", scope="col"), rx.el.th("Price", scope="col")),
border_bottom="2px solid gray",
),
rx.el.tbody(
rx.el.tr(rx.el.td("Latte"), rx.el.td("2", align="right"), rx.el.td("$9.00", align="right")),
rx.el.tr(rx.el.td("Bagel"), rx.el.td("1", align="right"), rx.el.td("$3.50", align="right")),
),
rx.el.tfoot(
rx.el.tr(rx.el.th("Total", scope="row", col_span=2), rx.el.td("$12.50", align="right", font_weight="bold")),
border_top="2px solid gray",
),
width="300px",
text_align="left",
font_variant_numeric="tabular-nums",
style={"& col:last-child": {"width": "70px"}}, # see the colgroup example above
)Notas del taller
table > (caption) > thead · tbody · tfoot > tr > th · td. Los tr van siempre dentro de tbody u otro grupo.
Con preflight, la tabla no tiene ni bordes ni relleno. Pon border·padding tú.
Une celdas con col_span·row_span y no pongas celdas en los huecos ocupados.
El scope de th y el headers de td son asociaciones para los lectores de pantalla.
Si las filas vienen del State, crea los tr con rx.foreach. Para una tabla con estilo, rx.table.
Recibe avisos de nuevas lecciones
Te avisaremos por correo cuando este curso tenga lecciones nuevas o se abra un curso de continuación.
R
ReflexKR
Aprende Python y Reflex haciendo. Todos los ejemplos se ejecutaron y verificaron en Reflex 0.10.0.
ReflexKR es gratis y sin banners publicitarios. Si te ayudó, puedes apoyarlo con un café. ☕ Invítanos un café
Aviso de afiliados© 2026 ReflexKR · Since 2026 · CC BY-NC 4.0
Preguntas y respuestas
Pregunta lo que quieras sobre esta lección. Aquí se reúnen las preguntas de todas las versiones de idioma de esta página.