TableBody

Function TableBody 

Source
pub fn TableBody(_: TableBodyProps) -> Element
Available on crate feature dio only.
Expand description

A table body component that renders rows of data, along with loading and empty states.

This component is responsible for rendering the <tbody> section of a table in a Dioxus application. It dynamically displays row data, a loading message, or an empty state message based on the provided props.

§Props

  • columns: A Vec<Column> defining which fields to render in each table row. Each column corresponds to a key in the row data.
  • rows: A Vec<HashMap<&'static str, String>> representing the data for each row, where keys match column IDs.
  • loading: A bool flag that, when true, displays a loading message instead of data rows.
  • classes: A TableClasses struct for customizing the CSS class names of the body, rows, and cells.
  • texts: A TableTexts struct that provides custom text for the loading and empty states.

§Behavior

  • If loading is true, a single row with a loading message is shown spanning all columns.
  • If rows is empty and not loading, an empty message row is displayed.
  • Otherwise, each data row is rendered in a <tr>, with one <td> per column.

§Returns

A Dioxus Element representing the <tbody> of a table, with dynamic row content.

§Example

use dioxus::prelude::*;
use maplit::hashmap;
use table_rs::dioxus::table::Table;
use table_rs::dioxus::types::{Column, TableClasses, TableTexts};
use table_rs::dioxus::body::TableBody;


fn App() -> Element {
    let rows = vec![
        hashmap! { "name" => "Ferris".to_string(), "email" => "ferris@opensass.org".to_string() },
        hashmap! { "name" => "Rustacean".to_string(), "email" => "rust@opensass.org".to_string() },
    ];

    let columns = vec![
        Column { id: "name", header: "Name", ..Default::default() },
        Column { id: "email", header: "Email", ..Default::default() },
    ];

    rsx! {
        TableBody {
            columns: columns,
            rows: rows,
            loading: false,
            classes: TableClasses::default(),
            texts: TableTexts::default(),
        }
    }
}

§See Also

§Props

For details, see the props struct definition.