munza-x-data-grid 1.3.4 → 1.3.7
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/dist/README.md +257 -0
- package/dist/contexts/GridContext.d.ts +3 -1
- package/dist/core/Grid.d.ts +1 -1
- package/dist/data-grid.cjs +2 -2
- package/dist/data-grid.js +29 -24
- package/dist/index.css +334 -2
- package/package.json +4 -2
package/dist/README.md
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
# munza-x-data-grid
|
|
2
|
+
|
|
3
|
+
A flexible, feature-rich React data grid component built on top of [@tanstack/react-table](https://tanstack.com/table), with Tailwind CSS v4 styling and shadcn/ui primitives.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install munza-x-data-grid
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Import the stylesheet in your app entry point:
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
import 'munza-x-data-grid/style.css';
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Peer Dependencies
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install react react-dom
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Requires **React 18 or 19**.
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Basic Usage
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
import { Grid, useGridState, type ColumnDef } from 'munza-x-data-grid';
|
|
33
|
+
import 'munza-x-data-grid/style.css';
|
|
34
|
+
|
|
35
|
+
type Person = {
|
|
36
|
+
firstName: string;
|
|
37
|
+
lastName: string;
|
|
38
|
+
age: number;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const columns: ColumnDef<Person>[] = [
|
|
42
|
+
{ accessorKey: 'firstName', header: 'First Name' },
|
|
43
|
+
{ accessorKey: 'lastName', header: 'Last Name' },
|
|
44
|
+
{ accessorKey: 'age', header: 'Age' },
|
|
45
|
+
];
|
|
46
|
+
|
|
47
|
+
const data: Person[] = [{ firstName: 'Alice', lastName: 'Smith', age: 30 }];
|
|
48
|
+
|
|
49
|
+
export default function App() {
|
|
50
|
+
const { state, handlers } = useGridState();
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<Grid
|
|
54
|
+
columns={columns}
|
|
55
|
+
payload={{ data, total: data.length }}
|
|
56
|
+
state={state}
|
|
57
|
+
{...handlers}
|
|
58
|
+
/>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## API Reference
|
|
66
|
+
|
|
67
|
+
### `<Grid />`
|
|
68
|
+
|
|
69
|
+
The top-level component that renders the full data grid.
|
|
70
|
+
|
|
71
|
+
| Prop | Type | Required | Description |
|
|
72
|
+
| ----------------------- | ------------------------------------------ | -------- | -------------------------------------------------------- |
|
|
73
|
+
| `columns` | `ColumnDef<T>[]` | ✅ | Column definitions (TanStack Table format) |
|
|
74
|
+
| `payload` | `{ data: T[], total: number }` | ✅ | Row data and total count for pagination |
|
|
75
|
+
| `state` | `Partial<TableState>` | ✅ | Controlled table state (from `useGridState`) |
|
|
76
|
+
| `onColumnFiltersChange` | `OnChangeFn<ColumnFiltersState>` | — | Callback for column filter changes |
|
|
77
|
+
| `onPaginationChange` | `OnChangeFn<PaginationState>` | — | Callback for pagination changes |
|
|
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
|
+
---
|
|
110
|
+
|
|
111
|
+
## Column Definitions
|
|
112
|
+
|
|
113
|
+
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.
|
|
114
|
+
|
|
115
|
+
### Filter Variants
|
|
116
|
+
|
|
117
|
+
Set `meta.filterVariant` on a column to control its filter UI:
|
|
118
|
+
|
|
119
|
+
```tsx
|
|
120
|
+
{
|
|
121
|
+
accessorKey: 'status',
|
|
122
|
+
header: 'Status',
|
|
123
|
+
meta: {
|
|
124
|
+
filterVariant: 'select', // dropdown filter
|
|
125
|
+
},
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
{
|
|
129
|
+
accessorKey: 'age',
|
|
130
|
+
header: 'Age',
|
|
131
|
+
meta: {
|
|
132
|
+
filterVariant: 'text', // text input filter
|
|
133
|
+
},
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Row Number Column
|
|
138
|
+
|
|
139
|
+
```tsx
|
|
140
|
+
{
|
|
141
|
+
accessorFn: (_row, index) => index + 1,
|
|
142
|
+
cell: ({ row }) => row.index + 1,
|
|
143
|
+
id: 'rowNumber',
|
|
144
|
+
header: '',
|
|
145
|
+
size: 54,
|
|
146
|
+
maxSize: 54,
|
|
147
|
+
enableColumnFilter: false,
|
|
148
|
+
}
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Checkbox Selection Column
|
|
152
|
+
|
|
153
|
+
```tsx
|
|
154
|
+
{
|
|
155
|
+
id: 'select',
|
|
156
|
+
header: ({ table }) => (
|
|
157
|
+
<Checkbox
|
|
158
|
+
checked={
|
|
159
|
+
table.getIsAllPageRowsSelected() ||
|
|
160
|
+
(table.getIsSomePageRowsSelected() && 'indeterminate')
|
|
161
|
+
}
|
|
162
|
+
onCheckedChange={(value) => table.toggleAllPageRowsSelected(!!value)}
|
|
163
|
+
aria-label="Select all"
|
|
164
|
+
/>
|
|
165
|
+
),
|
|
166
|
+
cell: ({ row }) => (
|
|
167
|
+
<Checkbox
|
|
168
|
+
checked={row.getIsSelected()}
|
|
169
|
+
onCheckedChange={(value) => row.toggleSelected(!!value)}
|
|
170
|
+
aria-label="Select row"
|
|
171
|
+
/>
|
|
172
|
+
),
|
|
173
|
+
size: 40,
|
|
174
|
+
maxSize: 40,
|
|
175
|
+
enableColumnFilter: false,
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
## Server-Side Pagination
|
|
182
|
+
|
|
183
|
+
Set `manualPagination` to `true` and pass `payload.total` as the full server-side count.
|
|
184
|
+
|
|
185
|
+
```tsx
|
|
186
|
+
<Grid
|
|
187
|
+
columns={columns}
|
|
188
|
+
payload={{ data: serverData, total: serverTotal }}
|
|
189
|
+
state={state}
|
|
190
|
+
{...handlers}
|
|
191
|
+
manualPagination={true}
|
|
192
|
+
/>
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
The built-in pagination UI supports the following page sizes:
|
|
196
|
+
|
|
197
|
+
```
|
|
198
|
+
20, 30, 40, 50, 60, 70, 80, 90, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
---
|
|
202
|
+
|
|
203
|
+
## Expandable Rows
|
|
204
|
+
|
|
205
|
+
```tsx
|
|
206
|
+
<Grid
|
|
207
|
+
columns={columns}
|
|
208
|
+
payload={payload}
|
|
209
|
+
state={state}
|
|
210
|
+
{...handlers}
|
|
211
|
+
getRowCanExpand={(row) => !!row.original.subRows?.length}
|
|
212
|
+
renderSubComponent={({ row }) => (
|
|
213
|
+
<div className="p-4">
|
|
214
|
+
<pre>{JSON.stringify(row.original, null, 2)}</pre>
|
|
215
|
+
</div>
|
|
216
|
+
)}
|
|
217
|
+
/>
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
## Column Pinning
|
|
223
|
+
|
|
224
|
+
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.
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## Default Column Sizing
|
|
229
|
+
|
|
230
|
+
| Property | Default |
|
|
231
|
+
| --------- | ------- |
|
|
232
|
+
| `size` | `180px` |
|
|
233
|
+
| `minSize` | `180px` |
|
|
234
|
+
| `maxSize` | `180px` |
|
|
235
|
+
|
|
236
|
+
Override per-column:
|
|
237
|
+
|
|
238
|
+
```tsx
|
|
239
|
+
{
|
|
240
|
+
accessorKey: 'id',
|
|
241
|
+
size: 60,
|
|
242
|
+
minSize: 60,
|
|
243
|
+
maxSize: 60,
|
|
244
|
+
}
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
---
|
|
248
|
+
|
|
249
|
+
## TypeScript
|
|
250
|
+
|
|
251
|
+
All props and hooks are fully typed. Import types directly from the package:
|
|
252
|
+
|
|
253
|
+
```ts
|
|
254
|
+
import type { ColumnDef } from 'munza-x-data-grid';
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
TanStack Table types (`Row`, `TableState`, `PaginationState`, etc.) are re-exported and available from `@tanstack/react-table`.
|
|
@@ -4,6 +4,7 @@ export interface GridContextProps<T> {
|
|
|
4
4
|
table: Table<T>;
|
|
5
5
|
isLoading?: boolean;
|
|
6
6
|
isError?: boolean;
|
|
7
|
+
isFetching?: boolean;
|
|
7
8
|
paneRef1: React.RefObject<HTMLDivElement | null>;
|
|
8
9
|
paneRef2: React.RefObject<HTMLDivElement | null>;
|
|
9
10
|
globalFilter?: string;
|
|
@@ -27,11 +28,12 @@ interface GridContextProviderProps<T> {
|
|
|
27
28
|
manualPagination?: boolean;
|
|
28
29
|
isLoading?: boolean;
|
|
29
30
|
isError?: boolean;
|
|
31
|
+
isFetching?: boolean;
|
|
30
32
|
setGlobalFilter?: React.Dispatch<React.SetStateAction<string>>;
|
|
31
33
|
renderSubComponent?: (props: {
|
|
32
34
|
row: Row<T>;
|
|
33
35
|
}) => React.ReactElement;
|
|
34
36
|
getRowCanExpand?: (row: Row<T>) => boolean;
|
|
35
37
|
}
|
|
36
|
-
export declare const GridContextProvider: <T>({ children, payload, columns, state, onColumnFiltersChange, onPaginationChange, onSortingChange, setGlobalFilter, manualPagination, isError, isLoading, getRowCanExpand, renderSubComponent, }: GridContextProviderProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
38
|
+
export declare const GridContextProvider: <T>({ children, payload, columns, state, onColumnFiltersChange, onPaginationChange, onSortingChange, setGlobalFilter, manualPagination, isError, isLoading, isFetching, getRowCanExpand, renderSubComponent, }: GridContextProviderProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
37
39
|
export default GridContext;
|
package/dist/core/Grid.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { GridProps } from '../types';
|
|
2
|
-
declare const Grid: <T>({ columns, payload, state, onColumnFiltersChange, onPaginationChange, onSortingChange, isLoading, isError, setGlobalFilter, getRowCanExpand, renderSubComponent, manualPagination, }: GridProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
2
|
+
declare const Grid: <T>({ columns, payload, state, onColumnFiltersChange, onPaginationChange, onSortingChange, isLoading, isError, setGlobalFilter, getRowCanExpand, renderSubComponent, manualPagination, isFetching, }: GridProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
3
3
|
export { Grid };
|