Tables are used to organize and display data efficiently. The table component differs from the `data_table`` component in that it is not meant to display large amounts of data. It is meant to display data in a more organized way.
Tables can be created with a shorthand syntax or by explicitly creating the table components. The shorthand syntax is great for simple tables, but if you need more control over the table you can use the explicit syntax.
Let's start with the shorthand syntax.
The shorthand syntax has headers
, rows
, and footers
props.
Name | Age | Location |
---|---|---|
John | 30 | New York |
Jane | 31 | San Francisco |
Joe | 32 | Los Angeles |
Footer 1 | Footer 2 | Footer 3 |
rc.table_container(
rc.table(
headers=["Name", "Age", "Location"],
rows=[
("John", 30, "New York"),
("Jane", 31, "San Francisco"),
("Joe", 32, "Los Angeles"),
],
footers=["Footer 1", "Footer 2", "Footer 3"],
variant="striped",
)
)
Let's create a simple table explicitly. In this example we will make a table with 2 columns: Name
and Age
.
Name | Age |
---|---|
John | 30 |
rc.table(
rc.thead(
rc.tr(
rc.th("Name"),
rc.th("Age"),
)
),
rc.tbody(
rc.tr(
rc.td("John"),
rc.td(30),
)
),
)
In the examples we will be using this data to display in a table.
columns = ["Name", "Age", "Location"] data = [ ["John", 30, "New York"], ["Jane", 25, "San Francisco"], ] footer = ["Footer 1", "Footer 2", "Footer 3"]
Now lets create a table with the data we created.
Name | Age | Location |
---|---|---|
John | 30 | New York |
Jane | 25 | San Francisco |
Footer 1 | Footer 2 | Footer 3 |
Tables can also be styled with the variant and color_scheme arguments.
Name | Age | Location |
---|---|---|
John | 30 | New York |
Jane | 31 | San Francisco |
Joe | 32 | Los Angeles |
rc.table_container(
rc.table(
rc.thead(
rc.tr(
rc.th("Name"),
rc.th("Age"),
rc.th("Location"),
)
),
rc.tbody(
rc.tr(
rc.td("John"),
rc.td(30),
rc.td("New York"),
),
rc.tr(
rc.td("Jane"),
rc.td(31),
rc.td("San Francisco"),
),
rc.tr(
rc.td("Joe"),
rc.td(32),
rc.td("Los Angeles"),
),
),
variant="striped",
color_scheme="teal",
)
)
rc.Thead
A table header component.
Props
No component specific props
Event Triggers
See the full list of default event triggersrc.Tbody
A table body component.
Props
No component specific props
Event Triggers
See the full list of default event triggersrc.Tfoot
A table footer component.
Props
No component specific props
Event Triggers
See the full list of default event triggersrc.Tr
A table row component.
Props
No component specific props
Event Triggers
See the full list of default event triggersrc.TableContainer
The table container component renders a div that wraps the table component.
Props
No component specific props