@chumsinc/sortable-tables 2.1.2 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +87 -48
- package/README.md +94 -4
- package/dist/DataTable.d.ts +6 -6
- package/dist/DataTableCell.d.ts +299 -295
- package/dist/DataTableCols.d.ts +5 -0
- package/dist/DataTableContext.d.ts +10 -0
- package/dist/DataTableHead.d.ts +2 -2
- package/dist/DataTableProvider.d.ts +12 -0
- package/dist/DataTableRow.d.ts +1 -1
- package/dist/DataTableTBody.d.ts +1 -1
- package/dist/DataTableTH.d.ts +6 -6
- package/dist/RowsPerPage.d.ts +0 -1
- package/dist/SortableTable.d.ts +6 -6
- package/dist/SortableTableHead.d.ts +6 -6
- package/dist/SortableTableHeadWrapper.d.ts +9 -0
- package/dist/SortableTableTH.d.ts +6 -6
- package/dist/StandaloneDataTable.d.ts +6 -0
- package/dist/StandaloneSortHelper.d.ts +5 -0
- package/dist/StandaloneSortableTable.d.ts +6 -0
- package/dist/Table.d.ts +6 -5
- package/dist/index.cjs.js +30 -28
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +20 -10
- package/dist/index.es.js +521 -388
- package/dist/index.es.js.map +1 -1
- package/dist/types.d.ts +104 -105
- package/dist/useField.d.ts +6 -0
- package/dist/useTableContext.d.ts +2 -0
- package/dist/useTableFields.d.ts +9 -0
- package/dist/useTableSort.d.ts +9 -0
- package/eslint.config.mjs +3 -3
- package/package.json +7 -5
- package/src/DataTable.tsx +23 -28
- package/src/DataTableCell.tsx +33 -28
- package/src/DataTableCols.tsx +18 -0
- package/src/DataTableContext.ts +13 -0
- package/src/DataTableHead.tsx +9 -9
- package/src/DataTableProvider.tsx +62 -0
- package/src/DataTableRow.tsx +10 -8
- package/src/DataTableTBody.tsx +1 -5
- package/src/DataTableTH.tsx +11 -9
- package/src/RowsPerPage.tsx +6 -9
- package/src/SortableTable.tsx +26 -28
- package/src/SortableTableHead.tsx +17 -16
- package/src/SortableTableHeadWrapper.tsx +20 -0
- package/src/SortableTableTH.tsx +11 -8
- package/src/StandaloneDataTable.tsx +16 -0
- package/src/StandaloneSortHelper.tsx +15 -0
- package/src/StandaloneSortableTable.tsx +21 -0
- package/src/Table.tsx +49 -44
- package/src/TablePagination.tsx +4 -6
- package/src/index.tsx +26 -12
- package/src/types.ts +127 -128
- package/src/useField.ts +19 -0
- package/src/useTableContext.ts +10 -0
- package/src/useTableFields.ts +20 -0
- package/src/useTableSort.ts +20 -0
- package/test/Main.tsx +37 -0
- package/test/TableColumnsHandler.tsx +28 -0
- package/test/TestTable.tsx +51 -68
- package/test/data.ts +232 -232
- package/test/index.tsx +11 -11
- package/test/tableFields.tsx +52 -0
- package/test/utils.ts +19 -0
- package/tsconfig.json +1 -0
- package/vite.config.ts +1 -2
package/CHANGELOG.md
CHANGED
|
@@ -7,15 +7,54 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
9
9
|
|
|
10
|
-
#### [
|
|
10
|
+
#### [v3.0.0](https://github.com/ChumsInc/sortable-tables/compare/v2.2.0...v3.0.0)
|
|
11
|
+
|
|
12
|
+
> 2025-12-30
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Commits
|
|
18
|
+
|
|
19
|
+
- [`372fb75`](https://github.com/ChumsInc/sortable-tables/commit/372fb75f6401cdafe51a8c94bb725a9b5bb55054) Add DataTableProvider to allow for better modifying of columns.
|
|
20
|
+
- [`54f85e5`](https://github.com/ChumsInc/sortable-tables/commit/54f85e50d2390e7dfd2b9b3f4aad1a215abc51a5) Add DataTableProvider to allow for better modifying of columns.
|
|
21
|
+
- [`ca0dee4`](https://github.com/ChumsInc/sortable-tables/commit/ca0dee45c5f0e76c9239642e5946b171b0559fa0) chore: add type definitions for SortableTableHeadWrapper, declare component with displayName
|
|
22
|
+
- [`d5cb405`](https://github.com/ChumsInc/sortable-tables/commit/d5cb40577c6e9edbe84a0770af756b6e28d8ae5d) chore: replace "collapse" with "visible" for field visibility control, filter hidden fields in table rendering
|
|
23
|
+
- [`f8e67fb`](https://github.com/ChumsInc/sortable-tables/commit/f8e67fbc6f38cb8e457cb0f864abd3933b9f895b) chore: move field visibility filter to DataTableCell, simplify SortableTableHead rendering logic
|
|
24
|
+
- [`0d376b5`](https://github.com/ChumsInc/sortable-tables/commit/0d376b5567005ace9a64e14b6e593d5a7f617b20) chore: add StandaloneSortHelper to help handle sortChanges in StandaloneSortableTable component
|
|
25
|
+
- [`0780ecf`](https://github.com/ChumsInc/sortable-tables/commit/0780ecf033a3291e65d080915e14cb3c9812a1b6) chore: add testing for standalone tables
|
|
26
|
+
|
|
27
|
+
#### [v2.2.0](https://github.com/ChumsInc/sortable-tables/compare/v2.1.3...v2.2.0) - 2025-12-16
|
|
28
|
+
|
|
29
|
+
> 2025-12-16
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
### Commits
|
|
35
|
+
|
|
36
|
+
- [`78c1ccc`](https://github.com/ChumsInc/sortable-tables/commit/78c1ccc7fe0ccb1a98077ecdbbe75f21a8b08da5) chore: add new context-based table components and integrate TableProvider with useTableFields hook
|
|
37
|
+
|
|
38
|
+
#### [v2.1.3](https://github.com/ChumsInc/sortable-tables/compare/v2.1.2...v2.1.3) - 2025-12-15
|
|
39
|
+
|
|
40
|
+
> 2025-12-15
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
### Commits
|
|
46
|
+
|
|
47
|
+
- [`f4bdc3e`](https://github.com/ChumsInc/sortable-tables/commit/f4bdc3e6007cad72623eafe7d823cbb15c5edf68) chore: replace classnames with clsx, add DataTableCols declaration, add DataTableCols with option for visibility:collapse
|
|
48
|
+
|
|
49
|
+
#### [v2.1.2](https://github.com/ChumsInc/sortable-tables/compare/v2.1.1...v2.1.2) - 2025-12-02
|
|
11
50
|
|
|
12
51
|
> 2025-12-02
|
|
13
52
|
|
|
14
53
|
|
|
15
54
|
|
|
16
55
|
|
|
17
|
-
### Commits
|
|
18
|
-
|
|
56
|
+
### Commits
|
|
57
|
+
|
|
19
58
|
- [`210a01e`](https://github.com/ChumsInc/sortable-tables/commit/210a01e9cf4e62a63d569bd6ced41a26f17b5ae5) chore: update dependencies in package-lock.json
|
|
20
59
|
|
|
21
60
|
#### [v2.1.1](https://github.com/ChumsInc/sortable-tables/compare/v2.1.0...v2.1.1) - 2025-11-04
|
|
@@ -25,8 +64,8 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
25
64
|
|
|
26
65
|
|
|
27
66
|
|
|
28
|
-
### Commits
|
|
29
|
-
|
|
67
|
+
### Commits
|
|
68
|
+
|
|
30
69
|
- [`be79047`](https://github.com/ChumsInc/sortable-tables/commit/be79047541456eee2006706438b55aa61aed4fc1) chore: update types and dependencies
|
|
31
70
|
|
|
32
71
|
#### [v2.1.0](https://github.com/ChumsInc/sortable-tables/compare/v2.0.14...v2.1.0) - 2025-11-03
|
|
@@ -36,8 +75,8 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
36
75
|
|
|
37
76
|
|
|
38
77
|
|
|
39
|
-
### Commits
|
|
40
|
-
|
|
78
|
+
### Commits
|
|
79
|
+
|
|
41
80
|
- [`7b2a057`](https://github.com/ChumsInc/sortable-tables/commit/7b2a057454d2b46affe2cccfce060c7812065a23) migrate to vite library build
|
|
42
81
|
- [`ae562e9`](https://github.com/ChumsInc/sortable-tables/commit/ae562e9c631b94c367f87ff5df70e849ee0405a2) migrate to vite library build
|
|
43
82
|
|
|
@@ -48,8 +87,8 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
48
87
|
|
|
49
88
|
|
|
50
89
|
|
|
51
|
-
### Commits
|
|
52
|
-
|
|
90
|
+
### Commits
|
|
91
|
+
|
|
53
92
|
- [`48f4b1f`](https://github.com/ChumsInc/sortable-tables/commit/48f4b1f0df1e94a4eede5e1333a25262b28f4cdd) chore: npm updates, apply className attribute to rendered table.
|
|
54
93
|
|
|
55
94
|
#### [v2.0.13](https://github.com/ChumsInc/sortable-tables/compare/v2.0.12...v2.0.13) - 2025-07-08
|
|
@@ -59,8 +98,8 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
59
98
|
|
|
60
99
|
|
|
61
100
|
|
|
62
|
-
### Commits
|
|
63
|
-
|
|
101
|
+
### Commits
|
|
102
|
+
|
|
64
103
|
- [`4f9d4cc`](https://github.com/ChumsInc/sortable-tables/commit/4f9d4cc0cb6da9c27fa26c93bfd6ee302a70ff3c) fix: still trying to make it work for MouseEvent typing ... perhaps I should learn to write tests?
|
|
65
104
|
|
|
66
105
|
#### [v2.0.12](https://github.com/ChumsInc/sortable-tables/compare/v2.0.11...v2.0.12) - 2025-07-08
|
|
@@ -70,8 +109,8 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
70
109
|
|
|
71
110
|
|
|
72
111
|
|
|
73
|
-
### Commits
|
|
74
|
-
|
|
112
|
+
### Commits
|
|
113
|
+
|
|
75
114
|
- [`23062bc`](https://github.com/ChumsInc/sortable-tables/commit/23062bc7b9bb8764c1a83f96f3c1e75db292fbf4) fix: types.d.ts did not seem to get updated on last build
|
|
76
115
|
|
|
77
116
|
#### [v2.0.11](https://github.com/ChumsInc/sortable-tables/compare/v2.0.10...v2.0.11) - 2025-07-08
|
|
@@ -81,8 +120,8 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
81
120
|
|
|
82
121
|
|
|
83
122
|
|
|
84
|
-
### Commits
|
|
85
|
-
|
|
123
|
+
### Commits
|
|
124
|
+
|
|
86
125
|
- [`83848ad`](https://github.com/ChumsInc/sortable-tables/commit/83848ad28bad0dcd659f3a4bcf2a9ee1ab44d860) fix: add stricter typing for onSelectRow MouseEvent<HTMLTableRowElement>
|
|
87
126
|
|
|
88
127
|
#### [v2.0.10](https://github.com/ChumsInc/sortable-tables/compare/v2.0.9...v2.0.10) - 2025-07-07
|
|
@@ -92,8 +131,8 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
92
131
|
|
|
93
132
|
|
|
94
133
|
|
|
95
|
-
### Commits
|
|
96
|
-
|
|
134
|
+
### Commits
|
|
135
|
+
|
|
97
136
|
- [`8f314f4`](https://github.com/ChumsInc/sortable-tables/commit/8f314f4f89a0f47382de3a678b8ec124ac44ebdf) fix: allow key modifiers to be passed on onSelectRow
|
|
98
137
|
- [`7267ff2`](https://github.com/ChumsInc/sortable-tables/commit/7267ff20a6a233043919c53e46113f5300dea9af) fix: allow key modifiers to be passed on onSelectRow
|
|
99
138
|
|
|
@@ -104,8 +143,8 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
104
143
|
|
|
105
144
|
|
|
106
145
|
|
|
107
|
-
### Commits
|
|
108
|
-
|
|
146
|
+
### Commits
|
|
147
|
+
|
|
109
148
|
- [`08001a6`](https://github.com/ChumsInc/sortable-tables/commit/08001a6604fea9ae723147f36a54261d798153c8) fix: add correct fields type for SortableTableProps, npm updates
|
|
110
149
|
|
|
111
150
|
#### [v2.0.8](https://github.com/ChumsInc/sortable-tables/compare/v2.0.7...v2.0.8) - 2025-03-13
|
|
@@ -115,8 +154,8 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
115
154
|
|
|
116
155
|
|
|
117
156
|
|
|
118
|
-
### Commits
|
|
119
|
-
|
|
157
|
+
### Commits
|
|
158
|
+
|
|
120
159
|
- [`ad120cd`](https://github.com/ChumsInc/sortable-tables/commit/ad120cd7f521d194613370aa91befd24582aef5d) fix: allow React.ReactNode for rowsPerPage label
|
|
121
160
|
|
|
122
161
|
#### [v2.0.7](https://github.com/ChumsInc/sortable-tables/compare/v2.0.6...v2.0.7) - 2025-02-27
|
|
@@ -126,8 +165,8 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
126
165
|
|
|
127
166
|
|
|
128
167
|
|
|
129
|
-
### Commits
|
|
130
|
-
|
|
168
|
+
### Commits
|
|
169
|
+
|
|
131
170
|
- [`2350125`](https://github.com/ChumsInc/sortable-tables/commit/2350125f5fca9545c2ca1136191af5f765313e4f) fix: always show datacell contents if the render attribute is not undefined.
|
|
132
171
|
- [`3ffa14a`](https://github.com/ChumsInc/sortable-tables/commit/3ffa14a3f1648173a9d8c896abe886c26928506e) chore: npm updates
|
|
133
172
|
- [`364895d`](https://github.com/ChumsInc/sortable-tables/commit/364895dd31a6aa4a8b8d4911b965323637a7e85f) chore: update README.md
|
|
@@ -142,11 +181,11 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
142
181
|
|
|
143
182
|
|
|
144
183
|
|
|
145
|
-
### Commits
|
|
146
|
-
|
|
147
|
-
- [`4d7716d`](https://github.com/ChumsInc/sortable-tables/commit/4d7716d5d23eac513b3761c03b722aeba250019b) fix: Accessibility fixes
|
|
148
|
-
- aria labels for pagination buttons
|
|
149
|
-
- allow set table cell as TD or TH
|
|
184
|
+
### Commits
|
|
185
|
+
|
|
186
|
+
- [`4d7716d`](https://github.com/ChumsInc/sortable-tables/commit/4d7716d5d23eac513b3761c03b722aeba250019b) fix: Accessibility fixes
|
|
187
|
+
- aria labels for pagination buttons
|
|
188
|
+
- allow set table cell as TD or TH
|
|
150
189
|
- set scope on sortable table header cell
|
|
151
190
|
|
|
152
191
|
#### [v2.0.5](https://github.com/ChumsInc/sortable-tables/compare/v2.0.4...v2.0.5) - 2025-02-07
|
|
@@ -156,8 +195,8 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
156
195
|
|
|
157
196
|
|
|
158
197
|
|
|
159
|
-
### Commits
|
|
160
|
-
|
|
198
|
+
### Commits
|
|
199
|
+
|
|
161
200
|
- [`cd6ae46`](https://github.com/ChumsInc/sortable-tables/commit/cd6ae4690642081d649933f3a6828f180db50cc3) fix: RowsPerPage select element was missing id attribute
|
|
162
201
|
|
|
163
202
|
#### [v2.0.4](https://github.com/ChumsInc/sortable-tables/compare/v2.0.3...v2.0.4) - 2025-02-06
|
|
@@ -167,11 +206,11 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
167
206
|
|
|
168
207
|
|
|
169
208
|
|
|
170
|
-
### Commits
|
|
171
|
-
|
|
172
|
-
- [`82a8737`](https://github.com/ChumsInc/sortable-tables/commit/82a87377d0a63ae4ea4826a7842640c3efc19d6c) feat:
|
|
173
|
-
- add responsive option
|
|
174
|
-
- add sort indicator alignment
|
|
209
|
+
### Commits
|
|
210
|
+
|
|
211
|
+
- [`82a8737`](https://github.com/ChumsInc/sortable-tables/commit/82a87377d0a63ae4ea4826a7842640c3efc19d6c) feat:
|
|
212
|
+
- add responsive option
|
|
213
|
+
- add sort indicator alignment
|
|
175
214
|
- add testing (visual, not automated)
|
|
176
215
|
- [`4f31f68`](https://github.com/ChumsInc/sortable-tables/commit/4f31f68f59875bfde20e7a3bf828b0e41c91bba0) feat: Show sort icon on hover.
|
|
177
216
|
- [`116487f`](https://github.com/ChumsInc/sortable-tables/commit/116487f5edd46c47eedc721c6feb2b71e92c189c) feat: Show sort icon on hover over the TH
|
|
@@ -183,8 +222,8 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
183
222
|
|
|
184
223
|
|
|
185
224
|
|
|
186
|
-
### Commits
|
|
187
|
-
|
|
225
|
+
### Commits
|
|
226
|
+
|
|
188
227
|
- [`b3e03b4`](https://github.com/ChumsInc/sortable-tables/commit/b3e03b4887b87c7cf744be4fda396cb2f41d7e1d) feat: Show sort icon on hover.
|
|
189
228
|
|
|
190
229
|
#### [v2.0.2](https://github.com/ChumsInc/sortable-tables/compare/v2.0.1...v2.0.2) - 2025-02-05
|
|
@@ -194,8 +233,8 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
194
233
|
|
|
195
234
|
|
|
196
235
|
|
|
197
|
-
### Commits
|
|
198
|
-
|
|
236
|
+
### Commits
|
|
237
|
+
|
|
199
238
|
- [`6127c13`](https://github.com/ChumsInc/sortable-tables/commit/6127c13ef9c987b28e64c6883ea3c2e12026c9ff) fix: ensure thProps.className gets applied to SortableTH
|
|
200
239
|
|
|
201
240
|
#### v2.0.1 - 2025-02-05
|
|
@@ -205,19 +244,19 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
205
244
|
|
|
206
245
|
|
|
207
246
|
|
|
208
|
-
### Commits
|
|
209
|
-
|
|
247
|
+
### Commits
|
|
248
|
+
|
|
210
249
|
- [`319cf62`](https://github.com/ChumsInc/sortable-tables/commit/319cf620ace584d7a1a5962879d007da898c0905) Initial commit
|
|
211
250
|
- [`76ff58a`](https://github.com/ChumsInc/sortable-tables/commit/76ff58a7005dfea279dbdbb04303b3fca65bcc22) initial commit, time for testing.
|
|
212
|
-
- [`d8639dc`](https://github.com/ChumsInc/sortable-tables/commit/d8639dc51c0373a1123b5e5b751caa89f2873b6a) fix: add dist directory
|
|
213
|
-
- updates to package.json
|
|
251
|
+
- [`d8639dc`](https://github.com/ChumsInc/sortable-tables/commit/d8639dc51c0373a1123b5e5b751caa89f2873b6a) fix: add dist directory
|
|
252
|
+
- updates to package.json
|
|
214
253
|
- updates to tsconfig.json
|
|
215
|
-
- [`e314afe`](https://github.com/ChumsInc/sortable-tables/commit/e314afefd0bb93f493867daca924bcba4992e78e) features:
|
|
216
|
-
- include TablePagination element
|
|
217
|
-
- RowsPerPage select
|
|
254
|
+
- [`e314afe`](https://github.com/ChumsInc/sortable-tables/commit/e314afefd0bb93f493867daca924bcba4992e78e) features:
|
|
255
|
+
- include TablePagination element
|
|
256
|
+
- RowsPerPage select
|
|
218
257
|
- add displayName to each component
|
|
219
|
-
- [`472dac4`](https://github.com/ChumsInc/sortable-tables/commit/472dac4f942d729db8cabccfd15d50acf0ec9d90) fixes
|
|
220
|
-
- add label option for RowsPerPage
|
|
258
|
+
- [`472dac4`](https://github.com/ChumsInc/sortable-tables/commit/472dac4f942d729db8cabccfd15d50acf0ec9d90) fixes
|
|
259
|
+
- add label option for RowsPerPage
|
|
221
260
|
- update TablePagination layout
|
|
222
261
|
- [`29d01eb`](https://github.com/ChumsInc/sortable-tables/commit/29d01eb21114a805c75e64838497c8f309676879) fix: add xs table size
|
|
223
262
|
- [`ef2b963`](https://github.com/ChumsInc/sortable-tables/commit/ef2b963564efd036d052acde54e471d4319aa46e) chore: Update README to specific to that package.
|
package/README.md
CHANGED
|
@@ -8,10 +8,10 @@ This components uses [Bootstrap 5.3](https://getbootstrap.com/docs/5.3/content/t
|
|
|
8
8
|
additional table size 'xs' for less padding.
|
|
9
9
|
|
|
10
10
|
## Usage
|
|
11
|
-
|
|
11
|
+
### Configure Columns
|
|
12
12
|
```tsx
|
|
13
|
-
import {
|
|
14
|
-
import {ProductLine} from 'chums-
|
|
13
|
+
import {StandaloneSortableTable, SortableTableField, SortProps} from "@chumsinc/sortable-tables";
|
|
14
|
+
import {ProductLine} from 'chums-types'
|
|
15
15
|
|
|
16
16
|
const fields: SortableTableField<ProductLine>[] = [
|
|
17
17
|
{field: 'ProductLine', title: 'Prod Line', sortable: true, as: 'th'},
|
|
@@ -38,6 +38,94 @@ const fields: SortableTableField<ProductLine>[] = [
|
|
|
38
38
|
align: 'end'
|
|
39
39
|
},
|
|
40
40
|
];
|
|
41
|
+
```
|
|
42
|
+
### Usage in a DataTableProvider
|
|
43
|
+
```tsx
|
|
44
|
+
export default function Main() {
|
|
45
|
+
const dispatch = useAppDispatch();
|
|
46
|
+
const initialSort: SortProps<ProductLine> = {field: 'ProductLine', ascending: true};
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<DataTableProvider initialFields={tableFields} initialSort={initialSort}>
|
|
50
|
+
<TestTable />
|
|
51
|
+
</DataTableProvider>
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function TestTable() {
|
|
56
|
+
const dispatch = useAppDispatch();
|
|
57
|
+
const data = useAppSelector(selectSortedProductLines);
|
|
58
|
+
const sort = useAppSelector(selectProductLinesSort);
|
|
59
|
+
const [page, setPage] = useState(0);
|
|
60
|
+
const [rowsPerPage, setRowsPerPage] = useState(5);
|
|
61
|
+
const [, setCurrentSort] = useTableSort<ProductLine>();
|
|
62
|
+
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
setCurrentSort(sort);
|
|
65
|
+
setPage(0)
|
|
66
|
+
}, [sort, setCurrentSort])
|
|
67
|
+
|
|
68
|
+
const rowsPerPageChangeHandler = (rpp: number) => {
|
|
69
|
+
setPage(0);
|
|
70
|
+
setRowsPerPage(rpp);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const sortChangeHandler = (sort: SortProps<ProductLine>) => {
|
|
74
|
+
dispatch(setProductLinesSort(sort));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<div>
|
|
80
|
+
<TableColumnsHandler/>
|
|
81
|
+
<SortableTable onChangeSort={sortChangeHandler} size="lg" responsive
|
|
82
|
+
data={data.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)}
|
|
83
|
+
keyField="ProductLine" rowClassName={rowClassName}/>
|
|
84
|
+
<TablePagination page={page} onChangePage={setPage} size="sm"
|
|
85
|
+
rowsPerPage={rowsPerPage}
|
|
86
|
+
rowsPerPageProps={{
|
|
87
|
+
onChange: rowsPerPageChangeHandler,
|
|
88
|
+
label: <span className="bi-images" aria-label="Images Per Page"></span>,
|
|
89
|
+
pageValues: [5, 10, 15, 25, 50, 100]
|
|
90
|
+
}}
|
|
91
|
+
showFirst={data.length > rowsPerPage}
|
|
92
|
+
showLast={data.length > rowsPerPage}
|
|
93
|
+
count={data.length}/>
|
|
94
|
+
</div>
|
|
95
|
+
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function TableColumnsHandler() {
|
|
100
|
+
const [getField, updateField] = useTableContext<ProductLine>();
|
|
101
|
+
const [collapse, setCollapse] = React.useState<boolean>(getField('ProductLineDesc')?.collapse ?? false);
|
|
102
|
+
const id = useId();
|
|
103
|
+
|
|
104
|
+
const toggleFieldCollapse = useCallback((key: string, next: boolean) => {
|
|
105
|
+
console.debug('toggleFieldVisibility', key, next);
|
|
106
|
+
updateField(key, (prev) => ({...prev, collapse: next}))
|
|
107
|
+
setCollapse(next);
|
|
108
|
+
}, [updateField]);
|
|
109
|
+
|
|
110
|
+
const handleVisibleChange = (ev: React.ChangeEvent<HTMLInputElement>) => {
|
|
111
|
+
toggleFieldCollapse('ProductLineDesc', ev.target.checked);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return (
|
|
115
|
+
<div style={{display: 'flex', alignItems: 'center', justifyContent: 'flex-start', gap: '1rem'}}>
|
|
116
|
+
<input type="checkbox" checked={collapse} id={id} onChange={handleVisibleChange}/>
|
|
117
|
+
<label htmlFor={id}>Hide Description</label>
|
|
118
|
+
</div>
|
|
119
|
+
)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
```
|
|
124
|
+
### Usage as a Standalone Table:
|
|
125
|
+
```tsx
|
|
126
|
+
import {StandaloneSortableTable, SortableTableField, SortProps} from "@chumsinc/sortable-tables";
|
|
127
|
+
import {ProductLine} from 'chums-type'
|
|
128
|
+
import {fields} from './fields'
|
|
41
129
|
|
|
42
130
|
export default function ProductLinesList() {
|
|
43
131
|
const [sort, setSort] = useState<SortProps<ProductLine>>({field: 'ProductLine', ascending: true});
|
|
@@ -58,7 +146,7 @@ export default function ProductLinesList() {
|
|
|
58
146
|
|
|
59
147
|
return (
|
|
60
148
|
<div>
|
|
61
|
-
<
|
|
149
|
+
<StandaloneSortableTable currentSort={sort} onChangeSort={setSort} fields={fields} size="lg" responsive
|
|
62
150
|
data={list.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)}
|
|
63
151
|
keyField="ProductLine" rowClassName={rowClassName}/>
|
|
64
152
|
<TablePagination page={page} onChangePage={setPage} size="sm"
|
|
@@ -75,8 +163,10 @@ export default function ProductLinesList() {
|
|
|
75
163
|
}
|
|
76
164
|
```
|
|
77
165
|
|
|
166
|
+
##
|
|
78
167
|
## Breaking Changes
|
|
79
168
|
Breaking changes from `chums-components`
|
|
80
169
|
- TablePagination
|
|
81
170
|
- The rows per page options were moved to a new attribute `rowsPerPageProps`
|
|
82
171
|
- RowsPerPage now renders as a bootstrap InputGroup element
|
|
172
|
+
- For old standalone tables without the ContextProvider use version 2.1.3
|
package/dist/DataTable.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { DataTableProps } from './types';
|
|
2
|
-
declare function DataTable<T = unknown>({
|
|
3
|
-
declare namespace DataTable {
|
|
4
|
-
var displayName: string;
|
|
5
|
-
}
|
|
6
|
-
export default DataTable;
|
|
1
|
+
import { DataTableProps } from './types';
|
|
2
|
+
declare function DataTable<T = unknown>({ className, size, responsive, sticky, data, keyField, rowClassName, renderRow, onSelectRow, selected, tableHeadProps, children, tfoot, ...rest }: Omit<DataTableProps<T>, 'fields'>): import("react/jsx-runtime").JSX.Element;
|
|
3
|
+
declare namespace DataTable {
|
|
4
|
+
var displayName: string;
|
|
5
|
+
}
|
|
6
|
+
export default DataTable;
|