pub fn TableHeader(_: TableHeaderProps) -> Element
Available on crate feature
dio
only.Expand description
A table header component that renders sortable column headers for use within the Table
component.
This component produces the <thead>
section of a table using the provided column definitions,
handling rendering, sorting indicators (aria-sort
), and user interaction to trigger sort changes.
§Props
columns
: AVec<Column>
defining the columns to display in the header. EachColumn
may be sortable and have optional styles or class overrides.sort_column
: ASignal<Option<&'static str>>
indicating which column (if any) is currently being sorted.sort_order
: ASignal<SortOrder>
indicating the current sort direction (Asc
orDesc
).on_sort_column
: AnEventHandler<&'static str>
triggered when a sortable header cell is clicked. The column ID is passed as the event payload.classes
: ATableClasses
struct allowing custom class names for<thead>
,<tr>
, and<th>
elements.
§Behavior
- Sortable columns show proper
aria-sort
attributes for accessibility (ascending
,descending
, ornone
). - Clicking a sortable column emits an event to update sort state.
- Each column can override default styles and classes via
Column::style
andColumn::class
.
§Returns
Returns a Dioxus
Element
containing the <thead>
with all column headers rendered as <th>
elements.
§Example
use dioxus::prelude::*;
use maplit::hashmap;
use table_rs::dioxus::table::Table;
use table_rs::dioxus::types::{Column, TableClasses, SortOrder};
use table_rs::dioxus::header::TableHeader;
fn App() -> Element {
let columns = vec![
Column { id: "name", header: "Name", sortable: true, ..Default::default() },
Column { id: "email", header: "Email", sortable: false, ..Default::default() },
];
let sort_column = use_signal(|| Some("name"));
let sort_order = use_signal(|| SortOrder::Asc);
rsx! {
TableHeader {
columns: columns,
sort_column: sort_column,
sort_order: sort_order,
on_sort_column: move |col_id| println!("Sort column changed: {}", col_id),
classes: TableClasses::default(),
}
}
}
§See Also
§Props
For details, see the props struct definition.
columns
:Vec<Column>
sort_column
:Signal<Option<&'staticstr>>
sort_order
:Signal<SortOrder>
on_sort_column
:EventHandler<&'staticstr>
classes
:TableClasses