Skip to content

Commit 89bdc40

Browse files
committed
updated generic example
1 parent 767cc48 commit 89bdc40

3 files changed

Lines changed: 20 additions & 17 deletions

File tree

.idea/leptos-struct-table.iml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/generic/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7-
leptos = { version = "0.5", features = ["nightly", "csr"] }
7+
leptos = { version = "0.6", features = ["nightly", "csr"] }
88
leptos-struct-table = { path = "../..", features = ["chrono", "uuid"] }
99
chrono = { version = "0.4", features = ["serde"] }
1010
console_error_panic_hook = "0.1"
1111
console_log = "1"
1212
log = "0.4"
13-
serde = "1"
1413
async-trait = "0.1"
1514

1615
[dev-dependencies]

examples/generic/src/main.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
//! Generic showcase example.
22
33
use crate::uuid::Uuid;
4-
use async_trait::async_trait;
54
use chrono::NaiveDate;
65
use leptos::*;
76
use 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)]
1311
pub struct Book<T>
1412
where
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)]
4242
pub 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

Comments
 (0)