1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
use crate::;
use *;
/// Describes how a single column renders, filters, and sorts rows.
///
/// This is the main trait you implement to define a column's behavior. Each column
/// is a self-contained unit that can:
/// - Render its header and cells
/// - Filter rows based on custom logic
/// - Sort rows with custom comparison
/// - Hold its own reactive state via `Signal`
///
/// # Type Parameter
///
/// - `R`: The row type this column works with (must implement [`Row`])
///
/// # Example
///
/// ```
/// use dioxus::prelude::*;
/// use dioxus_tabular::*;
///
/// #[derive(Clone, PartialEq)]
/// struct Product {
/// id: u32,
/// name: String,
/// price: u32,
/// }
///
/// impl Row for Product {
/// fn key(&self) -> impl Into<String> {
/// self.id.to_string()
/// }
/// }
///
/// #[derive(Clone, PartialEq)]
/// struct Price(u32);
///
/// impl GetRowData<Price> for Product {
/// fn get(&self) -> Price {
/// Price(self.price)
/// }
/// }
///
/// // A column that displays and sorts by price
/// #[derive(Clone, PartialEq)]
/// struct PriceColumn;
///
/// impl<R: Row + GetRowData<Price>> TableColumn<R> for PriceColumn {
/// fn column_name(&self) -> String {
/// "price".into()
/// }
///
/// fn render_header(&self, _context: ColumnContext, attributes: Vec<Attribute>) -> Element {
/// rsx! { th { ..attributes, "Price" } }
/// }
///
/// fn render_cell(&self, _context: ColumnContext, row: &R, attributes: Vec<Attribute>) -> Element {
/// rsx! { td { ..attributes, "¥{row.get().0}" } }
/// }
///
/// fn compare(&self, a: &R, b: &R) -> std::cmp::Ordering {
/// a.get().0.cmp(&b.get().0)
/// }
/// }
/// ```
///
/// # Filtering Example
///
/// ```
/// # use dioxus::prelude::*;
/// # use dioxus_tabular::*;
/// # #[derive(Clone, PartialEq)]
/// # struct Product { price: u32, id: u32 }
/// # impl Row for Product {
/// # fn key(&self) -> impl Into<String> { self.id.to_string() }
/// # }
/// # #[derive(Clone, PartialEq)]
/// # struct Price(u32);
/// # impl GetRowData<Price> for Product {
/// # fn get(&self) -> Price { Price(self.price) }
/// # }
/// #[derive(Clone, PartialEq)]
/// struct PriceColumn {
/// min_price: Signal<u32>,
/// }
///
/// impl<R: Row + GetRowData<Price>> TableColumn<R> for PriceColumn {
/// fn column_name(&self) -> String {
/// "price".into()
/// }
///
/// fn render_header(&self, _context: ColumnContext, attributes: Vec<Attribute>) -> Element {
/// rsx! { th { ..attributes, "Price" } }
/// }
///
/// fn render_cell(&self, _context: ColumnContext, row: &R, attributes: Vec<Attribute>) -> Element {
/// rsx! { td { ..attributes, "¥{row.get().0}" } }
/// }
///
/// // Only show rows with price >= min_price
/// fn filter(&self, row: &R) -> bool {
/// row.get().0 >= *self.min_price.read()
/// }
/// }
/// ```