Trait leptos_struct_table::TableRow
source · pub trait TableRow: Clone {
type ClassesProvider: TableClassesProvider + Copy;
const COLUMN_COUNT: usize;
// Required methods
fn render_row(
&self,
index: usize,
on_change: EventHandler<ChangeEvent<Self>>,
) -> impl IntoView;
fn render_head_row<F>(
sorting: Signal<VecDeque<(usize, ColumnSort)>>,
on_head_click: F,
) -> impl IntoView
where F: Fn(TableHeadEvent) + Clone + 'static;
fn col_name(col_index: usize) -> &'static str;
// Provided method
fn sorting_to_sql(sorting: &VecDeque<(usize, ColumnSort)>) -> Option<String> { ... }
}
Expand description
This trait has to implemented in order for [TableContent
] to be able to render rows and the head row of the table.
Usually this is done by #[derive(TableRow, Clone)]
.
Please see the simple example for how to use.
Required Associated Types§
Required Associated Constants§
sourceconst COLUMN_COUNT: usize
const COLUMN_COUNT: usize
How many columns this row has (i.e. the number of fields in the struct)
Required Methods§
sourcefn render_row(
&self,
index: usize,
on_change: EventHandler<ChangeEvent<Self>>,
) -> impl IntoView
fn render_row( &self, index: usize, on_change: EventHandler<ChangeEvent<Self>>, ) -> impl IntoView
Renders the inner of one row of the table using the cell renderers.
This produces the children that go into the row_renderer
given to [TableContent
].
This render function has to render exactly one root element.
sourcefn render_head_row<F>(
sorting: Signal<VecDeque<(usize, ColumnSort)>>,
on_head_click: F,
) -> impl IntoView
fn render_head_row<F>( sorting: Signal<VecDeque<(usize, ColumnSort)>>, on_head_click: F, ) -> impl IntoView
Render the head row of the table.
sourcefn col_name(col_index: usize) -> &'static str
fn col_name(col_index: usize) -> &'static str
The name of the column (= struct field name) at the given index. This can be used to implement
sorting in a database. It takes the #[table(skip)]
attributes into account. col_index
refers to the index of the field in the struct while ignoring skipped ones.
For example:
#[derive(TableRow, Clone)]
struct Person {
#[table(skip)]
id: i64, // -> ignored
name: String, // -> col_index = 0
#[table(skip)]
internal: usize, // -> ignored
age: u16, // -> col_index = 1
}
assert_eq!(Person::col_name(0), "name");
assert_eq!(Person::col_name(1), "age");
Provided Methods§
sourcefn sorting_to_sql(sorting: &VecDeque<(usize, ColumnSort)>) -> Option<String>
fn sorting_to_sql(sorting: &VecDeque<(usize, ColumnSort)>) -> Option<String>
Converts the given sorting to an SQL statement.
Return None
when there is nothing to be sorted otherwise Some("ORDER BY ...")
.
Uses Self::col_name
to get the column names for sorting.