11//! Generic showcase example.
22
33use crate :: uuid:: Uuid ;
4- use async_trait:: async_trait;
54use chrono:: NaiveDate ;
65use leptos:: * ;
76use leptos_struct_table:: * ;
8- use serde:: { de:: DeserializeOwned , Deserialize , Serialize } ;
9- use std:: fmt:: Debug ;
107
118/// This generates the component BookTable
12- #[ derive( TableComponent , Serialize , Deserialize , Debug , Clone , Default , PartialEq ) ]
9+ #[ derive( TableRow , Clone ) ]
10+ #[ table( impl_vec_data_provider) ]
1311pub struct Book < T >
1412where
15- // necessary trait bounds. `IntoView` is only necessary because we require it in our custom renderer below
16- // otherwise you could remove it here.
13+ // necessary trait bounds. `IntoView` is only necessary because we require it in
14+ // our custom renderer below, otherwise you could remove it here.
1715 // If you also make the table sortable then you might have to add `PartialOrd` as well.
18- T : PartialEq + Debug + Clone + Serialize + DeserializeOwned + IntoView + ' static ,
16+ T : IntoView + Clone + ' static ,
1917{
2018 /// Id of the entry.
21- #[ table( key) ]
2219 pub id : Uuid ,
2320 /// Title of the book.
2421 pub title : String ,
@@ -30,17 +27,20 @@ where
3027 #[ table( none_value = "-" ) ]
3128 pub description : Option < String > ,
3229
33- /// Generic field. You have to specify a custom renderer for a generic field
34- /// and provide this serde bound attribute.
30+ /// Generic field. You have to specify a custom renderer for a generic field.
31+ ///
32+ /// In case you need serde you also have to add
33+ /// ```
34+ /// #[serde(bound(deserialize = "T: DeserializeOwned"))]
35+ /// ```
3536 #[ table( renderer = "CustomDataRenderer" ) ]
36- #[ serde( bound( deserialize = "T: DeserializeOwned" ) ) ]
3737 pub custom_data : T ,
3838}
3939
4040#[ component]
4141#[ allow( unused_variables) ]
4242pub fn CustomDataRenderer < T , F > (
43- # [ prop ( into ) ] class : MaybeSignal < String > ,
43+ class : String ,
4444 #[ prop( into) ] value : MaybeSignal < T > ,
4545 on_change : F ,
4646 index : usize ,
@@ -59,7 +59,7 @@ fn main() {
5959 console_error_panic_hook:: set_once ( ) ;
6060
6161 mount_to_body ( || {
62- let items = create_rw_signal ( vec ! [
62+ let rows = vec ! [
6363 Book {
6464 id: Uuid :: default ( ) ,
6565 title: "The Great Gatsby" . to_string( ) ,
@@ -94,10 +94,12 @@ fn main() {
9494 description: None ,
9595 custom_data: "still a string" . to_string( ) ,
9696 } ,
97- ] ) ;
97+ ] ;
9898
9999 view ! {
100- <BookTable items=items />
100+ <table>
101+ <TableContent rows />
102+ </table>
101103 }
102104 } )
103105}
0 commit comments