Skip to content

Commit c051639

Browse files
committed
updated readme and changelog
1 parent d79243d commit c051639

File tree

3 files changed

+71
-68
lines changed

3 files changed

+71
-68
lines changed

CHANGELOG.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
# Changelog
22

3-
## [Unreleased]
3+
## [0.7.0] - 2024-02-08
44

55
### Features 🚀
66

77
- Virtualization — Only elements that are visible are rendered (with some extra for smooth scrolling).
8+
- Other display acceleration strategies like infinite scroll and pagination are implemented as well.
89
- Caching — Only rows that are visible are requested from the data source and then cached.
910
- Error handling — If an error occurs while loading data, it is displayed in a table row instead of the failed data.
10-
- Easy reloading — The data can be reloaded through calling `TableData::reload`.
11+
- Easy reloading — The data can be reloaded through the `ReloadController`.
1112

1213
### Breaking Changes 🛠️
1314

14-
- The table component now takes a `TableData` instead of `RwSignal<impl TableDataProvider>`.
15-
Anything that implements `TableDataProvider` can be passed to the table component and is automatically converted.
16-
- The trait `TableDataProvider` has been extended to accomodate all the new functionaliy.
17-
Please check it's documentation for more details.
15+
Everything? - sorry. This release is like half a rewrite with much less macro magic.
16+
Please check the docs and examples.
1817

1918
## [0.6.0] - 2023-11-02
2019

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ repository = "https://github.com/Synphonyte/leptos-struct-table"
1313

1414
[dependencies]
1515
leptos = { version = "0.6", features = ["nightly"] }
16-
leptos-struct-table-macro = { path = "../leptos-struct-table-macro" }
16+
leptos-struct-table-macro = "0.9"
1717
leptos-use = "0.10"
1818
async-trait = "0.1"
1919
paste = { version = "1.0", optional = true }

README.md

Lines changed: 65 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -14,43 +14,43 @@ Easily create Leptos table components from structs.
1414

1515
## Features
1616

17-
- **Async data loading** - The data is loaded asynchronously. This allows for loading data from a REST API or a database etc.
18-
- **Selectable** - Optional. You can enable single or multi-select.
19-
- **Fully Customizable** - You can customize every aspect of the table by plugging in your own components for rendering rows, cells, headers. See [Custom Renderers](#custom-renderers) for more information.
17+
- **Easy to use** - yet powerful.
18+
- **Async data loading** - The data is loaded asynchronously. This allows to load data from a REST API or a database etc.
19+
- **Selection** - Can be turned off or single/multi select
20+
- **Customization** - You can customize every aspect of the table by plugging in your own components for rendering rows, cells, headers. See [Custom Renderers](#custom-renderers) for more information.
2021
- **Headless** - No default styling is applied to the table. You can fully customize the classes that are applied to the table. See [Classes customization](#classes-customization) for more information.
2122
- **Sorting** - Optional. If turned on: Click on a column header to sort the table by that column. You can even sort by multiple columns.
2223
- **Virtualization** - Only the visible rows are rendered. This allows for very large tables.
23-
- **Editable** - Optional. You can provide custom renderers for editable cells. See [Editable Cells](#editable-cells) for more information.
24+
- **Pagination** - Instead of virtualization you can paginate the table.
25+
- **Caching** - Only visible rows are loaded and cached.
26+
- **Editing** - Optional. You can provide custom renderers for editable cells. See [Editable Cells](#editable-cells) for more information.
2427

2528
## Usage
2629

2730
```rust
2831
use leptos::*;
2932
use leptos_struct_table::*;
30-
use serde::{Deserialize, Serialize};
31-
use async_trait::async_trait;
3233

33-
// This generates the component PersonTable
34-
#[derive(TableComponent, Serialize, Deserialize, Debug, Clone, Default, PartialEq)]
34+
#[derive(TableRow, Clone)]
35+
#[table(impl_vec_data_provider)]
3536
pub struct Person {
36-
#[table(key)]
3737
id: u32,
3838
name: String,
3939
age: u32,
4040
}
4141

4242
fn main() {
4343
mount_to_body(|| {
44-
// Create a few Person items
45-
let items = create_rw_signal( vec![
44+
let rows = vec![
4645
Person { id: 1, name: "John".to_string(), age: 32 },
4746
Person { id: 2, name: "Jane".to_string(), age: 28 },
4847
Person { id: 3, name: "Bob".to_string(), age: 45 },
49-
]);
48+
];
5049

51-
// Use the generated component
5250
view! {
53-
<PersonTable items=items />
51+
<table>
52+
<TableContent rows />
53+
</table>
5454
}
5555
});
5656
}
@@ -64,32 +64,24 @@ The `#[table(...)]` attribute can be used to customize the generated component.
6464

6565
These attributes can be applied to the struct itself.
6666

67-
- **`sortable`** - Specifies that the table should be sortable. This makes the header clickable to toggle sorting.
68-
- **`selection_mode`** - Specifies the selection mode. Can be one of `none`, `single`, (TODO: `multiple`). Defaults to `none`.
69-
If given `single` then the generated component has a `selected_key: RwSignal<Option<K>>` property that can be used to get/set the selected key (of type K, the field specified by `#[table(key)]` - see below).
70-
Clicking on a row will set the selected key to the key of that row.
71-
- **`component_name`** - Specifies the name of the generated component. Defaults to `StructNameTable`.
72-
- **`classes_provider`** - Specifies the name of the class provider. Used to customize the classes that are applied to the table.
73-
For convenience sensible presets for major CSS frameworks are provided. See [`TableClassesProvider`] for more information.
74-
- **`tag`** - Specifies the tag that is used as the root element for the table. Defaults to `"table"`.
75-
- **`row_renderer`** - Specifies the name of the row renderer component. Used to customize the rendering of rows. Defaults to [`DefaultTableRowRenderer`].
76-
- **`head_row_renderer`** - Specifies the name of the head row renderer component/tag. Used to customize the rendering of the head rows. Defaults to the tag `tr`. This only takes a `class` attribute.
77-
- **`head_cell_renderer`** - Specifies the name of the header cell renderer component. Used to customize the rendering of header cells. Defaults to [`DefaultTableHeaderRenderer`].
78-
- **`thead_renderer`** - Specifies the name of the thead renderer component. Used to customize the rendering of the thead. Defaults to the tag `thead`. Takes no attributes.
79-
- **`tbody_renderer`** - Specifies the name of the tbody renderer component. Used to customize the rendering of the tbody. Defaults to the tag `tbody`. Takes no attributes.
80-
- **`row_class`** - Specifies the classes that are applied to each row. Can be used in conjuction with `classes_provider` to customize the classes.
81-
- **`head_row_class`** - Specifies the classes that are applied to the header row. Can be used in conjuction with `classes_provider` to customize the classes.
67+
- **`sortable`** - Specifies that the table should be sortable. This makes the header titles clickable to control sorting. See the [simple example](https://github.com/synphonyte/leptos-struct-table/blob/master/examples/simple/src/main.rs) for more information.
68+
- **`classes_provider`** - Specifies the name of the class provider. Used to quickly customize all of the classes that are applied to the table.
69+
For convenience sensible presets for major CSS frameworks are provided. See [`TableClassesProvider`] and [tailwind example](https://github.com/synphonyte/leptos-struct-table/blob/master/examples/tailwind/src/main.rs) for more information.
70+
- **`head_cell_renderer`** - Specifies the name of the header cell renderer component. Used to customize the rendering of header cells. Defaults to [`DefaultTableHeaderRenderer`]. See the [custom_renderers_svg example](https://github.com/Synphonyte/leptos-struct-table/blob/master/examples/custom_renderers_svg/src/main.rs) for more information.
71+
- **`impl_vec_data_provider`** - If given, then [`TableDataProvider`] is automatically implemented for `Vec<ThisStruct>` to allow
72+
for easy local data use. See the [simple example](https://github.com/synphonyte/leptos-struct-table/blob/master/examples/simple/src/main.rs) for more information.
73+
- **`row_type`** - Specifies the type of the rows in the table. Defaults to the struct that this is applied to. See the [custom_type example](https://github.com/synphonyte/leptos-struct-table/blob/master/examples/custom_type/src/main.rs) for more information.
8274

8375
### Field attributes
8476

8577
These attributes can be applied to any field in the struct.
8678

87-
- **`key`** - Specifies the field that is used as the key for each row. This is required on exactly one field.
8879
- **`class`** - Specifies the classes that are applied to each cell (head and body) in the field's column. Can be used in conjuction with `classes_provider` to customize the classes.
8980
- **`head_class`** - Specifies the classes that are applied to the header cell in the field's column. Can be used in conjuction with `classes_provider` to customize the classes.
9081
- **`cell_class`** - Specifies the classes that are applied to the body cells in the field's column. Can be used in conjuction with `classes_provider` to customize the classes.
9182
- **`skip`** - Specifies that the field should be skipped. This is useful for fields that are not displayed in the table.
9283
- **`skip_sort`** - Only applies if `sortable` is set on the struct. Specifies that the field should not be used for sorting. Clicking it's header will not do anything.
84+
- **`skip_header`** - Makes the title of the field not be displayed in the head row.
9385
- **`title`** - Specifies the title that is displayed in the header cell. Defaults to the field name converted to title case (`this_field` becomes `"This Field"`).
9486
- **`renderer`** - Specifies the name of the cell renderer component. Used to customize the rendering of cells.
9587
Defaults to [`DefaultNumberTableCellRenderer`] for number types and [`DefaultTableCellRenderer`] for anything else.
@@ -115,10 +107,9 @@ You can also look at [`TailwindClassesPreset`] for an example how this can be im
115107
Example:
116108

117109
```rust
118-
#[derive(TableComponent, Serialize, Deserialize, Debug, Clone, Default, PartialEq)]
110+
#[derive(TableRow, Clone)]
119111
#[table(classes_provider = "TailwindClassesPreset")]
120112
pub struct Book {
121-
#[table(key)]
122113
id: u32,
123114
title: String,
124115
}
@@ -133,10 +124,9 @@ or the `getter` attribute.
133124
Let's start with [`FieldGetter`] and see an example:
134125

135126
```rust
136-
#[derive(TableComponent, Serialize, Deserialize, Debug, Clone, Default, PartialEq)]
127+
#[derive(TableRow, Clone)]
137128
#[table(classes_provider = "TailwindClassesPreset")]
138129
pub struct Book {
139-
#[table(key)]
140130
id: u32,
141131
title: String,
142132
author: String,
@@ -156,12 +146,9 @@ impl Book {
156146
To provide maximum flexibility you can use the `getter` attribute.
157147

158148
```rust
159-
#[derive(TableComponent, Serialize, Deserialize, Debug, Clone, Default, PartialEq)]
149+
#[derive(TableRow, Clone)]
160150
#[table(classes_provider = "TailwindClassesPreset")]
161151
pub struct Book {
162-
#[table(key)]
163-
id: u32,
164-
165152
// this tells the macro that you're going to provide a method called `get_title` that returns a `String`
166153
#[table(getter = "get_title")]
167154
title: String,
@@ -186,15 +173,21 @@ value you want to modify before it's rendered.
186173
## Custom Renderers
187174

188175
Custom renderers can be used to customize almost every aspect of the table.
189-
They are specified by using the various `...renderer` attributes on the struct or fields.
176+
They are specified by using the various `...renderer` attributes on the struct or fields or props of the [`TableContent`] component.
190177
To implement a custom renderer please have a look at the default renderers listed below.
191178

192-
On the struct level you can use these attributes:
193-
- **`row_renderer`** - Defaults to [`DefaultTableRowRenderer`].
194-
- **`head_row_renderer`** - Defaults to the tag `tr`. This only takes a `class` attribute.
195-
- **`head_cell_renderer`** - Defaults to [`DefaultTableHeaderRenderer`].
196-
- **`thead_renderer`** - Defaults to the tag `thead`. Takes no attributes.
179+
On the struct level you can use this attribute:
180+
- **`thead_cell_renderer`** - Defaults to [`DefaultTableHeaderCellRenderer`] which renders `<th><span>Title</span></th>`
181+
together with sorting functionality (if enabled).
182+
183+
As props of the [`TableContent`] component you can use the following:
184+
- **`thead_renderer`** - Defaults to [`DefaultTableHeadRenderer`] which just renders the tag `thead`.
185+
- **`thead_row_renderer`** - Defaults to [`DefaultTableHeadRowRenderer`] which just renders the tag `tr`.
197186
- **`tbody_renderer`** - Defaults to the tag `tbody`. Takes no attributes.
187+
- **`row_renderer`** - Defaults to [`DefaultTableRowRenderer`].
188+
- **`loading_row_renderer`** - Defaults to [`DefaultLoadingRowRenderer`].
189+
- **`error_row_renderer`** - Defaults to [`DefaultErrorRowRenderer`].
190+
- **`row_placeholder_renderer`** - Defaults to [`DefaultRowPlaceholderRenderer`].
198191

199192
On the field level you can use the **`renderer`** attribute.
200193

@@ -206,10 +199,8 @@ If the feature `chrono` is enabled then [`DefaultNaiveDateTableCellRenderer`], [
206199
Example:
207200

208201
```rust
209-
#[derive(TableComponent, Serialize, Deserialize, Debug, Clone, Default, PartialEq)]
202+
#[derive(TableRow, Clone)]
210203
pub struct Book {
211-
#[table(key)]
212-
id: u32,
213204
title: String,
214205
#[table(renderer = "ImageTableCellRenderer")]
215206
img: String,
@@ -218,7 +209,7 @@ pub struct Book {
218209
// Easy cell renderer that just displays an image from an URL.
219210
#[component]
220211
fn ImageTableCellRenderer<F>(
221-
#[prop(into)] class: MaybeSignal<String>,
212+
class: String,
222213
#[prop(into)] value: MaybeSignal<String>,
223214
on_change: F,
224215
index: usize,
@@ -234,19 +225,19 @@ where
234225
}
235226
```
236227

237-
For more detailed information please have a look at the `custom_renderers_svg` example for a complete customization.
228+
For more detailed information please have a look at the [custom_renderers_svg example](https://github.com/synphonyte/leptos-struct-table/blob/master/examples/custom_renderers_svg/src/main.rs) for a complete customization.
238229

239230

240-
#### Editable Cells
231+
### Editable Cells
241232

242233
You might have noticed the type parameter `F` in the custom cell renderer above. This can be used
243234
to emit an event when the cell is changed. In the simplest case you can use a cell renderer that
244235
uses an `<input>`.
245236

246237
```rust
247-
#[derive(TableComponent, Serialize, Deserialize, Debug, Clone, Default, PartialEq)]
238+
#[derive(TableRow, Clone, Default, Debug)]
239+
#[table(impl_vec_data_provider)]
248240
pub struct Book {
249-
#[table(key)]
250241
id: u32,
251242
#[table(renderer = "InputCellRenderer")]
252243
title: String,
@@ -255,7 +246,7 @@ pub struct Book {
255246
// Easy input cell renderer that emits `on_change` when the input is changed.
256247
#[component]
257248
fn InputCellRenderer<F>(
258-
#[prop(into)] class: MaybeSignal<String>,
249+
class: String,
259250
#[prop(into)] value: MaybeSignal<String>,
260251
on_change: F,
261252
index: usize,
@@ -269,25 +260,38 @@ where
269260
</td>
270261
}
271262
}
272-
```
273263

274-
Then in the table component you can listen to the `on_change` event:
275-
276-
```rust
264+
// Then in the table component you can listen to the `on_change` event:
277265

278266
#[component]
279267
pub fn App() -> impl IntoView {
280-
let on_change = move |evt: TableChangeEvent<Book, BookColumnName, BookColumnValue>| {
281-
// Do something
268+
let rows = vec![Book::default(), Book::default()];
269+
270+
let on_change = move |evt: ChangeEvent<Book>| {
271+
logging::log!("Changed row at index {}:\n{:#?}", evt.row_index, evt.changed_row);
282272
};
283273

284274
view! {
285-
<BookTable items=items on_change=on_change />
275+
<table>
276+
<TableContent rows on_change />
277+
</table>
286278
}
287279
}
288280
```
289281

290-
Please have a look at the `editable` example for fully working example.
282+
Please have a look at the [editable example](https://github.com/Synphonyte/leptos-struct-table/tree/master/examples/editable/src/main.rs) for fully working example.
283+
284+
## Pagination / Virtualization / InfiniteScroll
285+
286+
This table component supports different display acceleration strategies. You can set them through the `display_strategy` prop of
287+
the [`TableContent`] component.
288+
289+
The following options are available. Check their docs for more details.
290+
- [`DisplayStrategy::Virtualization`] (default)
291+
- [`DisplayStrategy::InfiniteScroll`]
292+
- [`DisplayStrategy::Pagination`]
293+
294+
Please have a look at the [pagination example](https://github.com/Synphonyte/leptos-struct-table/tree/master/examples/pagination/src/main.rs) for more information on how to use pagination.
291295

292296
## Contribution
293297

0 commit comments

Comments
 (0)