pub trait TableRow: Sized {
type ClassesProvider: TableClassesProvider + Copy;
const COLUMN_COUNT: usize;
// Required methods
fn render_row(row: RwSignal<Self>, index: usize) -> 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)]
.
Please see the simple example for how to use.
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 Associated Types§
Required Methods§
Sourcefn render_row(row: RwSignal<Self>, index: usize) -> impl IntoView
fn render_row(row: RwSignal<Self>, index: usize) -> 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)]
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.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.