Yew Table
A simple table component for the Yew web framework.
Usage
Use the Table component by setting the columns
and data
properties:
impl Renderable<Model> for Model {
fn view(&self) -> Html<Self> {
let columns = columns![
("id", "Id.")
("description", "Description")
("due_date", "Due date")
("status", "Status")
("is_favorite", "Fav.")
("is_archived", "Arch.")
];
html! {
<>
<Table<Task>: columns=columns, data=&self.tasks,/>
</>
}
}
}
Implement the TableData trait for the struct to be used:
#[derive(Default, Clone, PartialEq, Serialize)]
pub struct Task {
pub id: String,
}
impl TableData for Task {
fn get_field_as_html(&self, field_name: &str) -> Html<Table<Self>> {
match field_name {
"id" => html! {
{ &self.id }
},
}
}
}
Example
An example Yew app showing a plain table can be found in the examples folder. Just run the contained run.sh
script.
License
MIT © 2019 Alexis Luengas