munza-x-data-grid 2.0.2 → 3.0.0-beta.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 +77 -288
- package/dist/README.md +77 -288
- package/dist/components/ui/badge.d.ts +3 -3
- package/dist/components/ui/button.d.ts +3 -3
- package/dist/components/ui/checkbox.d.ts +2 -2
- package/dist/components/ui/input.d.ts +3 -0
- package/dist/components/ui/label.d.ts +2 -2
- package/dist/components/ui/popover.d.ts +10 -0
- package/dist/components/ui/skeleton.d.ts +1 -1
- package/dist/components/ui/spinner.d.ts +2 -0
- package/dist/components/ui/table.d.ts +10 -10
- package/dist/data-grid.cjs +6 -42
- package/dist/data-grid.js +2116 -6870
- package/dist/hooks/use-mobile.d.ts +1 -0
- package/dist/package/contexts/GridContext.d.ts +16 -0
- package/dist/package/grid/index.d.ts +3 -0
- package/dist/package/index.d.ts +3 -0
- package/dist/package/lib/queryBuilder.d.ts +76 -0
- package/dist/package/table/TMain.d.ts +2 -0
- package/dist/package/types/index.d.ts +8 -0
- package/package.json +88 -64
- package/dist/components/feedback/NoDataFoundMsg.d.ts +0 -2
- package/dist/components/feedback/TableError.d.ts +0 -2
- package/dist/components/feedback/TableErrorMsg.d.ts +0 -2
- package/dist/components/feedback/TableNoData.d.ts +0 -2
- package/dist/components/feedback/TableRowSkeleton.d.ts +0 -7
- package/dist/components/feedback/TableSkeleton.d.ts +0 -2
- package/dist/components/header/HeaderFilter.d.ts +0 -5
- package/dist/components/header/HeaderMenu.d.ts +0 -5
- package/dist/components/header/HeaderSort.d.ts +0 -5
- package/dist/components/pagination/index.d.ts +0 -4
- package/dist/components/table/TBody.d.ts +0 -2
- package/dist/components/table/TCell.d.ts +0 -6
- package/dist/components/table/THead.d.ts +0 -6
- package/dist/components/table/THeader.d.ts +0 -2
- package/dist/components/table/TMain.d.ts +0 -2
- package/dist/components/toolbar/ToolbarFilter.d.ts +0 -5
- package/dist/components/toolbar/index.d.ts +0 -2
- package/dist/components/ui/Input.d.ts +0 -3
- package/dist/components/ui/collapsible.d.ts +0 -5
- package/dist/components/ui/debounced-input.d.ts +0 -7
- package/dist/components/ui/dropdown-menu.d.ts +0 -29
- package/dist/components/ui/empty.d.ts +0 -11
- package/dist/components/ui/native-select.d.ts +0 -8
- package/dist/components/ui/separator.d.ts +0 -4
- package/dist/contexts/GridContext.d.ts +0 -43
- package/dist/core/Grid.d.ts +0 -3
- package/dist/hooks/useGrid.d.ts +0 -2
- package/dist/hooks/useGridState.d.ts +0 -19
- package/dist/hooks/useQueryArgs.d.ts +0 -12
- package/dist/hooks/useSyncScroll.d.ts +0 -7
- package/dist/index.css +0 -4
- package/dist/index.d.ts +0 -5
- package/dist/utils/buildQueryString.d.ts +0 -2
- package/dist/utils/buildSortString.d.ts +0 -4
- package/dist/utils/getPinStyles.d.ts +0 -3
package/README.md
CHANGED
|
@@ -1,288 +1,77 @@
|
|
|
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
|
-
| `onSortingChange` | `OnChangeFn<SortingState>` | — | Callback for sort changes |
|
|
79
|
-
| `setGlobalFilter` | `Dispatch<SetStateAction<string>>` | — | Callback to update the global search filter |
|
|
80
|
-
| `isLoading` | `boolean` | — | Displays a loading state |
|
|
81
|
-
| `isError` | `boolean` | — | Displays an error state |
|
|
82
|
-
| `manualPagination` | `boolean` | — | Set `true` for server-side pagination (default: `false`) |
|
|
83
|
-
| `getRowCanExpand` | `(row: Row<T>) => boolean` | — | Controls which rows are expandable |
|
|
84
|
-
| `renderSubComponent` | `(props: { row: Row<T> }) => ReactElement` | — | Renders expanded row content |
|
|
85
|
-
|
|
86
|
-
---
|
|
87
|
-
|
|
88
|
-
### `useGridState()`
|
|
89
|
-
|
|
90
|
-
Hook that provides controlled state and event handlers to pass into `<Grid />`.
|
|
91
|
-
|
|
92
|
-
```tsx
|
|
93
|
-
const { state, handlers } = useGridState();
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
**Returns:**
|
|
97
|
-
|
|
98
|
-
| Key | Description |
|
|
99
|
-
| ---------- | ----------------------------------------------------------------------------------------------------- |
|
|
100
|
-
| `state` | Partial `TableState` object (sorting, pagination, filters, etc.) |
|
|
101
|
-
| `handlers` | Object containing `onSortingChange`, `onPaginationChange`, `onColumnFiltersChange`, `setGlobalFilter` |
|
|
102
|
-
|
|
103
|
-
Spread `handlers` directly onto `<Grid />`:
|
|
104
|
-
|
|
105
|
-
```tsx
|
|
106
|
-
<Grid state={state} {...handlers} columns={columns} payload={payload} />
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
### Tailwind v4 Setup
|
|
110
|
-
|
|
111
|
-
If you're using Tailwind v4, add this to your `app.css` so Tailwind scans the grid's classes:
|
|
112
|
-
|
|
113
|
-
```css
|
|
114
|
-
@source "../node_modules/munza-x-data-grid/**/*.{js,ts,jsx,tsx}";
|
|
115
|
-
@theme inline {
|
|
116
|
-
--color-background: var(--background);
|
|
117
|
-
--color-foreground: var(--foreground);
|
|
118
|
-
--color-border: var(--border);
|
|
119
|
-
--color-muted: var(--muted);
|
|
120
|
-
--color-accent: var(--accent);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
:root {
|
|
124
|
-
--background: oklch(1 0 0);
|
|
125
|
-
--foreground: oklch(0.145 0 0);
|
|
126
|
-
--border: oklch(0.922 0 0);
|
|
127
|
-
--muted: oklch(0.97 0 0);
|
|
128
|
-
--accent: oklch(0.97 0 0);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
.dark {
|
|
132
|
-
--background: oklch(0.145 0 0);
|
|
133
|
-
--foreground: oklch(0.985 0 0);
|
|
134
|
-
--border: oklch(1 0 0 / 10%);
|
|
135
|
-
--muted: oklch(0.269 0 0);
|
|
136
|
-
--accent: oklch(0.269 0 0);
|
|
137
|
-
}
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
---
|
|
141
|
-
|
|
142
|
-
## Column Definitions
|
|
143
|
-
|
|
144
|
-
Columns follow the standard [TanStack Table `ColumnDef`](https://tanstack.com/table/latest/docs/api/core/column-def) format with an additional `meta` field for filter configuration.
|
|
145
|
-
|
|
146
|
-
### Filter Variants
|
|
147
|
-
|
|
148
|
-
Set `meta.filterVariant` on a column to control its filter UI:
|
|
149
|
-
|
|
150
|
-
```tsx
|
|
151
|
-
{
|
|
152
|
-
accessorKey: 'status',
|
|
153
|
-
header: 'Status',
|
|
154
|
-
meta: {
|
|
155
|
-
filterVariant: 'select', // dropdown filter
|
|
156
|
-
},
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
{
|
|
160
|
-
accessorKey: 'age',
|
|
161
|
-
header: 'Age',
|
|
162
|
-
meta: {
|
|
163
|
-
filterVariant: 'text', // text input filter
|
|
164
|
-
},
|
|
165
|
-
}
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
### Row Number Column
|
|
169
|
-
|
|
170
|
-
```tsx
|
|
171
|
-
{
|
|
172
|
-
accessorFn: (_row, index) => index + 1,
|
|
173
|
-
cell: ({ row }) => row.index + 1,
|
|
174
|
-
id: 'rowNumber',
|
|
175
|
-
header: '',
|
|
176
|
-
size: 54,
|
|
177
|
-
maxSize: 54,
|
|
178
|
-
enableColumnFilter: false,
|
|
179
|
-
}
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
### Checkbox Selection Column
|
|
183
|
-
|
|
184
|
-
```tsx
|
|
185
|
-
{
|
|
186
|
-
id: 'select',
|
|
187
|
-
header: ({ table }) => (
|
|
188
|
-
<Checkbox
|
|
189
|
-
checked={
|
|
190
|
-
table.getIsAllPageRowsSelected() ||
|
|
191
|
-
(table.getIsSomePageRowsSelected() && 'indeterminate')
|
|
192
|
-
}
|
|
193
|
-
onCheckedChange={(value) => table.toggleAllPageRowsSelected(!!value)}
|
|
194
|
-
aria-label="Select all"
|
|
195
|
-
/>
|
|
196
|
-
),
|
|
197
|
-
cell: ({ row }) => (
|
|
198
|
-
<Checkbox
|
|
199
|
-
checked={row.getIsSelected()}
|
|
200
|
-
onCheckedChange={(value) => row.toggleSelected(!!value)}
|
|
201
|
-
aria-label="Select row"
|
|
202
|
-
/>
|
|
203
|
-
),
|
|
204
|
-
size: 40,
|
|
205
|
-
maxSize: 40,
|
|
206
|
-
enableColumnFilter: false,
|
|
207
|
-
}
|
|
208
|
-
```
|
|
209
|
-
|
|
210
|
-
---
|
|
211
|
-
|
|
212
|
-
## Server-Side Pagination
|
|
213
|
-
|
|
214
|
-
Set `manualPagination` to `true` and pass `payload.total` as the full server-side count.
|
|
215
|
-
|
|
216
|
-
```tsx
|
|
217
|
-
<Grid
|
|
218
|
-
columns={columns}
|
|
219
|
-
payload={{ data: serverData, total: serverTotal }}
|
|
220
|
-
state={state}
|
|
221
|
-
{...handlers}
|
|
222
|
-
manualPagination={true}
|
|
223
|
-
/>
|
|
224
|
-
```
|
|
225
|
-
|
|
226
|
-
The built-in pagination UI supports the following page sizes:
|
|
227
|
-
|
|
228
|
-
```
|
|
229
|
-
20, 30, 40, 50, 60, 70, 80, 90, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000
|
|
230
|
-
```
|
|
231
|
-
|
|
232
|
-
---
|
|
233
|
-
|
|
234
|
-
## Expandable Rows
|
|
235
|
-
|
|
236
|
-
```tsx
|
|
237
|
-
<Grid
|
|
238
|
-
columns={columns}
|
|
239
|
-
payload={payload}
|
|
240
|
-
state={state}
|
|
241
|
-
{...handlers}
|
|
242
|
-
getRowCanExpand={(row) => !!row.original.subRows?.length}
|
|
243
|
-
renderSubComponent={({ row }) => (
|
|
244
|
-
<div className="p-4">
|
|
245
|
-
<pre>{JSON.stringify(row.original, null, 2)}</pre>
|
|
246
|
-
</div>
|
|
247
|
-
)}
|
|
248
|
-
/>
|
|
249
|
-
```
|
|
250
|
-
|
|
251
|
-
---
|
|
252
|
-
|
|
253
|
-
## Column Pinning
|
|
254
|
-
|
|
255
|
-
Column pinning is managed internally by the grid. No additional configuration is required — use the built-in toolbar UI to pin columns left or right.
|
|
256
|
-
|
|
257
|
-
---
|
|
258
|
-
|
|
259
|
-
## Default Column Sizing
|
|
260
|
-
|
|
261
|
-
| Property | Default |
|
|
262
|
-
| --------- | ------- |
|
|
263
|
-
| `size` | `180px` |
|
|
264
|
-
| `minSize` | `180px` |
|
|
265
|
-
| `maxSize` | `180px` |
|
|
266
|
-
|
|
267
|
-
Override per-column:
|
|
268
|
-
|
|
269
|
-
```tsx
|
|
270
|
-
{
|
|
271
|
-
accessorKey: 'id',
|
|
272
|
-
size: 60,
|
|
273
|
-
minSize: 60,
|
|
274
|
-
maxSize: 60,
|
|
275
|
-
}
|
|
276
|
-
```
|
|
277
|
-
|
|
278
|
-
---
|
|
279
|
-
|
|
280
|
-
## TypeScript
|
|
281
|
-
|
|
282
|
-
All props and hooks are fully typed. Import types directly from the package:
|
|
283
|
-
|
|
284
|
-
```ts
|
|
285
|
-
import type { ColumnDef } from 'munza-x-data-grid';
|
|
286
|
-
```
|
|
287
|
-
|
|
288
|
-
TanStack Table types (`Row`, `TableState`, `PaginationState`, etc.) are re-exported and available from `@tanstack/react-table`.
|
|
1
|
+
# React + TypeScript + Vite
|
|
2
|
+
|
|
3
|
+
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
|
|
4
|
+
|
|
5
|
+
Currently, two official plugins are available:
|
|
6
|
+
|
|
7
|
+
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Oxc](https://oxc.rs)
|
|
8
|
+
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/)
|
|
9
|
+
|
|
10
|
+
## React Compiler
|
|
11
|
+
|
|
12
|
+
The React Compiler is enabled on this template. See [this documentation](https://react.dev/learn/react-compiler) for more information.
|
|
13
|
+
|
|
14
|
+
Note: This will impact Vite dev & build performances.
|
|
15
|
+
|
|
16
|
+
## Expanding the ESLint configuration
|
|
17
|
+
|
|
18
|
+
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
|
|
19
|
+
|
|
20
|
+
```js
|
|
21
|
+
export default defineConfig([
|
|
22
|
+
globalIgnores(['dist']),
|
|
23
|
+
{
|
|
24
|
+
files: ['**/*.{ts,tsx}'],
|
|
25
|
+
extends: [
|
|
26
|
+
// Other configs...
|
|
27
|
+
|
|
28
|
+
// Remove tseslint.configs.recommended and replace with this
|
|
29
|
+
tseslint.configs.recommendedTypeChecked,
|
|
30
|
+
// Alternatively, use this for stricter rules
|
|
31
|
+
tseslint.configs.strictTypeChecked,
|
|
32
|
+
// Optionally, add this for stylistic rules
|
|
33
|
+
tseslint.configs.stylisticTypeChecked,
|
|
34
|
+
|
|
35
|
+
// Other configs...
|
|
36
|
+
],
|
|
37
|
+
languageOptions: {
|
|
38
|
+
parserOptions: {
|
|
39
|
+
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
|
40
|
+
tsconfigRootDir: import.meta.dirname,
|
|
41
|
+
},
|
|
42
|
+
// other options...
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
])
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
|
|
50
|
+
|
|
51
|
+
```js
|
|
52
|
+
// eslint.config.js
|
|
53
|
+
import reactX from 'eslint-plugin-react-x'
|
|
54
|
+
import reactDom from 'eslint-plugin-react-dom'
|
|
55
|
+
|
|
56
|
+
export default defineConfig([
|
|
57
|
+
globalIgnores(['dist']),
|
|
58
|
+
{
|
|
59
|
+
files: ['**/*.{ts,tsx}'],
|
|
60
|
+
extends: [
|
|
61
|
+
// Other configs...
|
|
62
|
+
// Enable lint rules for React
|
|
63
|
+
reactX.configs['recommended-typescript'],
|
|
64
|
+
// Enable lint rules for React DOM
|
|
65
|
+
reactDom.configs.recommended,
|
|
66
|
+
],
|
|
67
|
+
languageOptions: {
|
|
68
|
+
parserOptions: {
|
|
69
|
+
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
|
70
|
+
tsconfigRootDir: import.meta.dirname,
|
|
71
|
+
},
|
|
72
|
+
// other options...
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
])
|
|
76
|
+
|
|
77
|
+
```
|