mui-universal-table 1.0.9 → 2.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/README.md +5 -156
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -103,163 +103,12 @@ Each header object can have the following properties:
|
|
|
103
103
|
| `openIcon` | `element` | Custom icon for expanding |
|
|
104
104
|
| `closeIcon` | `element` | Custom icon for collapsing |
|
|
105
105
|
|
|
106
|
-
## Advanced
|
|
106
|
+
## Advanced Usage
|
|
107
107
|
|
|
108
|
-
|
|
108
|
+
Advanced usage examples (row selection, custom cells, and sub-tables) plus async/server-side guidance have moved to the docs site:
|
|
109
109
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
data={data}
|
|
113
|
-
headers={headers}
|
|
114
|
-
name="Selectable Users"
|
|
115
|
-
selectRows={true}
|
|
116
|
-
selectID="id"
|
|
117
|
-
onSelection={(selectedIds) => {
|
|
118
|
-
console.log("Selected:", selectedIds);
|
|
119
|
-
}}
|
|
120
|
-
/>
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
### With Custom Cell Rendering
|
|
124
|
-
|
|
125
|
-
```jsx
|
|
126
|
-
const headers = [
|
|
127
|
-
{ id: "name", label: "Name", searchable: true },
|
|
128
|
-
{
|
|
129
|
-
id: "status",
|
|
130
|
-
label: "Status",
|
|
131
|
-
component: (row) => (
|
|
132
|
-
<Chip
|
|
133
|
-
label={row.status}
|
|
134
|
-
color={row.status === "active" ? "success" : "default"}
|
|
135
|
-
/>
|
|
136
|
-
),
|
|
137
|
-
},
|
|
138
|
-
];
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
### With Sub-tables
|
|
142
|
-
|
|
143
|
-
```jsx
|
|
144
|
-
const headers = [
|
|
145
|
-
{ id: "name", label: "Department", searchable: true },
|
|
146
|
-
{
|
|
147
|
-
id: "employees",
|
|
148
|
-
label: "Employees",
|
|
149
|
-
subRow: true,
|
|
150
|
-
headers: [
|
|
151
|
-
{ id: "name", label: "Employee Name", searchable: true },
|
|
152
|
-
{ id: "role", label: "Role" },
|
|
153
|
-
],
|
|
154
|
-
},
|
|
155
|
-
];
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
````
|
|
159
|
-
|
|
160
|
-
The callback receives `{ searchTerm, direction, column, pages }`.
|
|
161
|
-
|
|
162
|
-
## Async / Server-side Mode
|
|
163
|
-
|
|
164
|
-
Set `asyncPages` to a positive number to enable server-side search and sort. Instead of filtering the data in-browser, the table calls `setLoading` with a payload object so your API handler can fetch the correct page.
|
|
165
|
-
|
|
166
|
-
### Payload shape
|
|
167
|
-
|
|
168
|
-
Every `setLoading` call in async mode passes the same object:
|
|
169
|
-
|
|
170
|
-
```ts
|
|
171
|
-
{
|
|
172
|
-
searchTerm: string, // current search input
|
|
173
|
-
column: string, // column id being sorted (empty string if none)
|
|
174
|
-
direction: "asc" | "desc",
|
|
175
|
-
pages: number, // value of the asyncPages prop
|
|
176
|
-
}
|
|
177
|
-
````
|
|
178
|
-
|
|
179
|
-
This payload is sent on:
|
|
180
|
-
|
|
181
|
-
- **Search** — debounced 500 ms after the user stops typing
|
|
182
|
-
- **Sort** — immediately when the user clicks a sortable column header
|
|
183
|
-
- **Reload** — when the user clicks the reload button (using the current search/sort state)
|
|
184
|
-
|
|
185
|
-
### Example
|
|
186
|
-
|
|
187
|
-
```jsx
|
|
188
|
-
function ServerSideTable() {
|
|
189
|
-
const [loading, setLoading] = React.useState(false);
|
|
190
|
-
const [data, setData] = React.useState([]);
|
|
191
|
-
|
|
192
|
-
const fetchData = async ({
|
|
193
|
-
searchTerm = "",
|
|
194
|
-
column = "",
|
|
195
|
-
direction = "asc",
|
|
196
|
-
pages = 1,
|
|
197
|
-
} = {}) => {
|
|
198
|
-
setLoading(true);
|
|
199
|
-
try {
|
|
200
|
-
const result = await myApi.getUsers({
|
|
201
|
-
searchTerm,
|
|
202
|
-
column,
|
|
203
|
-
direction,
|
|
204
|
-
pages,
|
|
205
|
-
});
|
|
206
|
-
setData(result);
|
|
207
|
-
} finally {
|
|
208
|
-
setLoading(false);
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
|
|
212
|
-
React.useEffect(() => {
|
|
213
|
-
fetchData();
|
|
214
|
-
}, []);
|
|
215
|
-
|
|
216
|
-
return (
|
|
217
|
-
<UniversalTable
|
|
218
|
-
data={data}
|
|
219
|
-
headers={headers}
|
|
220
|
-
name="Users"
|
|
221
|
-
loading={loading}
|
|
222
|
-
setLoading={fetchData}
|
|
223
|
-
asyncPages={1}
|
|
224
|
-
/>
|
|
225
|
-
);
|
|
226
|
-
}
|
|
227
|
-
```
|
|
228
|
-
|
|
229
|
-
> **Note:** When `asyncPages` is set, client-side search is disabled — the table renders whatever is in `data` as-is. For sorting, behaviour depends on the `sortable` flag on each header column (see below).
|
|
230
|
-
|
|
231
|
-
### Column-level sort behaviour in async mode
|
|
232
|
-
|
|
233
|
-
In async mode, each column independently controls whether sorting is handled by the server or the client:
|
|
234
|
-
|
|
235
|
-
| Header has `sortable: true` | Clicking the column header |
|
|
236
|
-
| --------------------------- | -------------------------------------------------------------------- |
|
|
237
|
-
| Yes | Calls `setLoading` with the sort payload — your API handles the sort |
|
|
238
|
-
| No (default) | Sorts the currently loaded `data` client-side |
|
|
239
|
-
|
|
240
|
-
This lets you mix server-sorted and client-sorted columns in the same table — for example, server-sort on a large indexed column while still allowing client-side sort on a small computed field.
|
|
241
|
-
|
|
242
|
-
```jsx
|
|
243
|
-
const headers = [
|
|
244
|
-
{ id: "name", label: "Name", searchable: true, sortable: true }, // → API
|
|
245
|
-
{ id: "status", label: "Status", sortable: true }, // → API
|
|
246
|
-
{ id: "localScore", label: "Score", numeric: true }, // → client-side
|
|
247
|
-
];
|
|
248
|
-
```
|
|
249
|
-
|
|
250
|
-
### Reload button
|
|
251
|
-
|
|
252
|
-
For the reload button, prefer providing an `onReload` callback. It takes priority over `setLoading` and gives you explicit control:
|
|
253
|
-
|
|
254
|
-
```jsx
|
|
255
|
-
<UniversalTable
|
|
256
|
-
...
|
|
257
|
-
onReload={() => fetchData({ searchTerm: currentSearch, column, direction, pages: 1 })}
|
|
258
|
-
reloadBtnLoading={loading}
|
|
259
|
-
/>
|
|
260
|
-
```
|
|
261
|
-
|
|
262
|
-
If you only provide `setLoading`, the reload button will call it with the current search/sort state automatically.
|
|
110
|
+
- https://skulldorom.github.io/MUI-universal-table/docs/advanced-usage
|
|
111
|
+
- https://skulldorom.github.io/MUI-universal-table/docs/async-usage
|
|
263
112
|
|
|
264
113
|
## License
|
|
265
114
|
|
|
@@ -267,7 +116,7 @@ MIT
|
|
|
267
116
|
|
|
268
117
|
## Documentation Site (Docusaurus)
|
|
269
118
|
|
|
270
|
-
This repository includes a Docusaurus site in `/
|
|
119
|
+
This repository includes a Docusaurus site in `/docs`.
|
|
271
120
|
|
|
272
121
|
Run it locally:
|
|
273
122
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mui-universal-table",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "A universal table component built with Material UI for React applications",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
"pack:local": "npm run build && npm pack",
|
|
35
35
|
"dev": "rollup -c -w",
|
|
36
36
|
"prepack": "npm run build",
|
|
37
|
-
"docs:start": "npm --prefix
|
|
38
|
-
"docs:build": "npm --prefix
|
|
39
|
-
"docs:serve": "npm --prefix
|
|
37
|
+
"docs:start": "npm --prefix docs run start",
|
|
38
|
+
"docs:build": "npm --prefix docs run build",
|
|
39
|
+
"docs:serve": "npm --prefix docs run serve",
|
|
40
40
|
"test": "node --experimental-vm-modules node_modules/jest-cli/bin/jest.js",
|
|
41
41
|
"test:watch": "node --experimental-vm-modules node_modules/jest-cli/bin/jest.js --watch",
|
|
42
42
|
"lint": "eslint src",
|