@chainsys/sab-react-grid 1.0.1
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/LICENSE +21 -0
- package/README.md +234 -0
- package/dist/cjs/SabReactTable.js +1192 -0
- package/dist/cjs/SabReactTable.js.map +1 -0
- package/dist/cjs/index.js +25 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/utils/exportUtils.js +85 -0
- package/dist/cjs/utils/exportUtils.js.map +1 -0
- package/dist/cjs/utils/tableColumnResizeUtils.js +153 -0
- package/dist/cjs/utils/tableColumnResizeUtils.js.map +1 -0
- package/dist/cjs/utils/tableFormatters.js +239 -0
- package/dist/cjs/utils/tableFormatters.js.map +1 -0
- package/dist/esm/SabReactTable.d.ts +46 -0
- package/dist/esm/SabReactTable.d.ts.map +1 -0
- package/dist/esm/SabReactTable.js +1163 -0
- package/dist/esm/SabReactTable.js.map +1 -0
- package/dist/esm/index.d.ts +10 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +9 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/utils/exportUtils.d.ts +17 -0
- package/dist/esm/utils/exportUtils.d.ts.map +1 -0
- package/dist/esm/utils/exportUtils.js +78 -0
- package/dist/esm/utils/exportUtils.js.map +1 -0
- package/dist/esm/utils/tableColumnResizeUtils.d.ts +21 -0
- package/dist/esm/utils/tableColumnResizeUtils.d.ts.map +1 -0
- package/dist/esm/utils/tableColumnResizeUtils.js +148 -0
- package/dist/esm/utils/tableColumnResizeUtils.js.map +1 -0
- package/dist/esm/utils/tableFormatters.d.ts +57 -0
- package/dist/esm/utils/tableFormatters.d.ts.map +1 -0
- package/dist/esm/utils/tableFormatters.js +231 -0
- package/dist/esm/utils/tableFormatters.js.map +1 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
# @chainsys/sab-react-grid
|
|
2
|
+
|
|
3
|
+
A professional, enterprise-grade data grid for React applications. Built on **TanStack Table** and **TanStack React Virtual**, it delivers high-performance tables with sorting, filtering, grouping, column visibility, virtualization, and Excel/CSV exportโwith a consistent API and minimal configuration.
|
|
4
|
+
|
|
5
|
+
**Package:** `@chainsys/sab-react-grid`
|
|
6
|
+
**Version:** 1.0.1
|
|
7
|
+
**License:** MIT
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
| Feature | Description |
|
|
14
|
+
|--------|-------------|
|
|
15
|
+
| **TanStack Table** | Full control over sorting, filtering, grouping, pagination, column visibility, order, and sizing |
|
|
16
|
+
| **Row virtualization** | Renders only visible rows via `@tanstack/react-virtual` for smooth scrolling with large datasets |
|
|
17
|
+
| **Layout modes** | `fit-default`, `fit-window`, or `fit-content` (content-based column widths) |
|
|
18
|
+
| **Column filters** | Text, number, date, datetime, time (Flatpickr), multiselect, checkbox, boolean, dropdown, and radio with operand support (contains, equals, greater than, etc.) |
|
|
19
|
+
| **Filter placeholders** | Search icon (๐๏ธ) for text/number and dropdown filters; calendar icon for date/datetime/time filters (with SVG placeholder when empty) |
|
|
20
|
+
| **Export** | Excel (`.xlsx`) via ExcelJS and CSV via plain Blob from the toolbar Data Export menu |
|
|
21
|
+
| **Grouping** | Drag columns into the grouping zone; expand/collapse groups |
|
|
22
|
+
| **Column reorder** | Drag-and-drop column reordering in the header |
|
|
23
|
+
| **Column visibility** | Show/hide columns from the Columns menu |
|
|
24
|
+
| **Sticky headers** | Header and filter rows stay fixed while the body scrolls |
|
|
25
|
+
| **Actions column** | Row actions (Add, View, Edit, Delete, List, or custom) with configurable icon, label, and navigation URL from `meta.actions` |
|
|
26
|
+
| **Performance** | Memoized header, filter, row, and cell components |
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npm install @chainsys/sab-react-grid @tanstack/react-table @tanstack/react-virtual react react-dom
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Peer dependencies
|
|
37
|
+
|
|
38
|
+
Install in your application if not already present:
|
|
39
|
+
|
|
40
|
+
- `react` (^18.0.0 or ^19.0.0)
|
|
41
|
+
- `react-dom` (^18.0.0 or ^19.0.0)
|
|
42
|
+
- `@tanstack/react-table` (^8.0.0)
|
|
43
|
+
- `@tanstack/react-virtual` (^3.0.0)
|
|
44
|
+
|
|
45
|
+
### Dependencies (installed automatically)
|
|
46
|
+
|
|
47
|
+
- `date-fns` โ date formatting
|
|
48
|
+
- `exceljs` โ Excel (.xlsx) export (larger files; NPM vulnerabilities mitigated via package overrides)
|
|
49
|
+
- `flatpickr`, `react-flatpickr` โ date/datetime/time filters
|
|
50
|
+
|
|
51
|
+
CSV export uses no extra libraries (plain string/Blob).
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Project structure and main files
|
|
56
|
+
|
|
57
|
+
| Path | Purpose |
|
|
58
|
+
|------|---------|
|
|
59
|
+
| `src/index.ts` | Package entry; re-exports component, formatters, export helpers, and types |
|
|
60
|
+
| `src/SabReactTable.tsx` | Main grid component: table UI, toolbar, filter row, virtualization, grouping, export menu |
|
|
61
|
+
| `src/utils/tableFormatters.tsx` | `DataFormatter`, `ActionFormatter`, date formatting, `TableAction` / `ACTION_ICON_KEYS` / `ActionIcons` |
|
|
62
|
+
| `src/utils/exportUtils.ts` | `exportTableToExcel` (ExcelJS), `exportTableToCSV` (plain Blob) |
|
|
63
|
+
| `src/utils/tableColumnResizeUtils.ts` | `resizeColumnsByCellContent`, `getWidthInPixel`, `getWidthInPixelTitle` for fit-to-content layout |
|
|
64
|
+
| `dist/` | Built output (ESM + CJS + types); `files` in package.json ships only `dist` |
|
|
65
|
+
|
|
66
|
+
**Build:** `npm run build` (runs `clean` then `build:esm` and `build:cjs`).
|
|
67
|
+
**Clean:** `npm run clean` removes `dist` before build to avoid stale artifacts.
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## Quick start
|
|
72
|
+
|
|
73
|
+
```tsx
|
|
74
|
+
import { SabReactTable } from '@chainsys/sab-react-grid'
|
|
75
|
+
import type { ColumnDef } from '@tanstack/react-table'
|
|
76
|
+
|
|
77
|
+
interface Person {
|
|
78
|
+
id: number
|
|
79
|
+
name: string
|
|
80
|
+
email: string
|
|
81
|
+
role: string
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const columns: ColumnDef<Person, unknown>[] = [
|
|
85
|
+
{ id: 'id', accessorKey: 'id', header: 'ID' },
|
|
86
|
+
{ id: 'name', accessorKey: 'name', header: 'Name' },
|
|
87
|
+
{ id: 'email', accessorKey: 'email', header: 'Email' },
|
|
88
|
+
{ id: 'role', accessorKey: 'role', header: 'Role', meta: { dataType: 'text' } },
|
|
89
|
+
]
|
|
90
|
+
|
|
91
|
+
const data: Person[] = [
|
|
92
|
+
{ id: 1, name: 'Alice', email: 'alice@example.com', role: 'Admin' },
|
|
93
|
+
{ id: 2, name: 'Bob', email: 'bob@example.com', role: 'User' },
|
|
94
|
+
]
|
|
95
|
+
|
|
96
|
+
export function MyTable() {
|
|
97
|
+
return (
|
|
98
|
+
<SabReactTable<Person>
|
|
99
|
+
data={data}
|
|
100
|
+
columns={columns}
|
|
101
|
+
title="Users"
|
|
102
|
+
defaultPageSize={50}
|
|
103
|
+
pageSizeOptions={[10, 20, 50, 100]}
|
|
104
|
+
initialLayoutMode="fit-content"
|
|
105
|
+
onSortedDataChange={(rows) => console.log('Filtered/sorted rows', rows)}
|
|
106
|
+
onRowClick={(row) => console.log('Clicked', row)}
|
|
107
|
+
/>
|
|
108
|
+
)
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## Props
|
|
115
|
+
|
|
116
|
+
| Prop | Type | Default | Description |
|
|
117
|
+
|------|------|---------|-------------|
|
|
118
|
+
| `data` | `TData[]` | *required* | Row data |
|
|
119
|
+
| `columns` | `ColumnDef<TData, any>[]` | *required* | TanStack Table column definitions |
|
|
120
|
+
| `title` | `string` | `'Table_List'` | Table title in the toolbar |
|
|
121
|
+
| `onSortedDataChange` | `(rows: TData[]) => void` | โ | Called with filtered/sorted rows (pre-pagination) |
|
|
122
|
+
| `defaultPageSize` | `number` | `50` | Initial page size |
|
|
123
|
+
| `pageSizeOptions` | `number[]` | `[10, 20, 50, 100, 500, 1000]` | Page size dropdown options |
|
|
124
|
+
| `groupingLabels` | `Record<string, string>` | `{}` | Display labels for grouping columns |
|
|
125
|
+
| `onRowClick` | `(row: TData) => void` | โ | Row click handler |
|
|
126
|
+
| `onActionClick` | `(actionId, row, action) => void` | โ | Handler for action buttons; use `action.navigate` or `action.id` to route |
|
|
127
|
+
| `initialLayoutMode` | `'fit-default' \| 'fit-window' \| 'fit-content'` | `'fit-content'` | Initial layout mode |
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## Column meta
|
|
132
|
+
|
|
133
|
+
Use the `meta` property on column definitions to control formatting and filtering:
|
|
134
|
+
|
|
135
|
+
| Meta key | Type | Description |
|
|
136
|
+
|----------|------|-------------|
|
|
137
|
+
| `dataType` | `'text' \| 'number' \| 'decimal' \| 'currency' \| 'email' \| 'boolean' \| 'date' \| 'datetime' \| 'time' \| 'percentage' \| 'icon-boolean'` | Cell formatting and alignment |
|
|
138
|
+
| `formatOptions` | `{ decimals?, currencySymbol?, dateFormat?, datetimeFormat?, timeFormat? }` | Number, currency, and date formatting |
|
|
139
|
+
| `filterType` | `'text' \| 'select' \| 'multiselect' \| 'checkbox' \| 'boolean' \| 'date' \| 'number' \| 'dropdown' \| 'radio'` | Filter UI type |
|
|
140
|
+
| `filterOptions` | `{ label: string; value: any }[]` | Options for select, multiselect, dropdown, and radio filters |
|
|
141
|
+
| `actions` | `TableAction[]` | Row action buttons (Add, View, Edit, Delete, List, or custom) |
|
|
142
|
+
|
|
143
|
+
### Filter placeholders
|
|
144
|
+
|
|
145
|
+
- **Text, number, and dropdown/select filters:** search placeholder (๐๏ธ).
|
|
146
|
+
- **Date, datetime, and time filters:** calendar icon (SVG) when empty, plus optional text placeholder; Flatpickr for picking date/time.
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## Actions (from config / JSON)
|
|
151
|
+
|
|
152
|
+
Actions are fully driven by column `meta.actions`. Each action can specify:
|
|
153
|
+
|
|
154
|
+
| Field | Type | Description |
|
|
155
|
+
|-------|------|-------------|
|
|
156
|
+
| `id` | `string` | Unique key passed to `onActionClick` |
|
|
157
|
+
| `label` | `string` | Button label (optional for icon-only buttons) |
|
|
158
|
+
| `icon` | `'View' \| 'Edit' \| 'Delete' \| 'Add' \| 'List'` or lowercase in JSON, or `ReactNode` | Built-in icon or custom node |
|
|
159
|
+
| `navigate` | `string \| (row) => string` | URL or function; use in `onActionClick` for routing (e.g. `router.push(...)`) |
|
|
160
|
+
| `onClick` | `(row) => void` | Per-action handler (if not using table `onActionClick`) |
|
|
161
|
+
| `show` | `(row) => boolean` | Hide button for specific rows |
|
|
162
|
+
| `className` | `string` | Extra CSS class for the button |
|
|
163
|
+
|
|
164
|
+
**Built-in icon keys:** `View`, `Edit`, `Delete`, `Add`, `List` (exported as `ACTION_ICON_KEYS`). In JSON you can use lowercase (`"view"`, `"add"`, etc.).
|
|
165
|
+
|
|
166
|
+
Example:
|
|
167
|
+
|
|
168
|
+
```tsx
|
|
169
|
+
meta: {
|
|
170
|
+
actions: [
|
|
171
|
+
{ id: 'add', label: 'Add', icon: 'Add', navigate: '/create' },
|
|
172
|
+
{ id: 'view', label: 'View', icon: 'View', navigate: (row) => `/item/${row.id}` },
|
|
173
|
+
{ id: 'edit', label: 'Edit', icon: 'Edit', navigate: (row) => `/edit/${row.id}` },
|
|
174
|
+
{ id: 'list', label: 'List', icon: 'List', navigate: '/list' },
|
|
175
|
+
],
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
## Example: filters and formatting
|
|
182
|
+
|
|
183
|
+
```tsx
|
|
184
|
+
const columns: ColumnDef<Person, unknown>[] = [
|
|
185
|
+
{ id: 'id', accessorKey: 'id', header: 'ID', meta: { dataType: 'number' } },
|
|
186
|
+
{ id: 'name', accessorKey: 'name', header: 'Name', meta: { dataType: 'text' } },
|
|
187
|
+
{ id: 'email', accessorKey: 'email', header: 'Email', meta: { dataType: 'email' } },
|
|
188
|
+
{
|
|
189
|
+
id: 'role',
|
|
190
|
+
accessorKey: 'role',
|
|
191
|
+
header: 'Role',
|
|
192
|
+
meta: {
|
|
193
|
+
dataType: 'text',
|
|
194
|
+
filterType: 'select',
|
|
195
|
+
filterOptions: [
|
|
196
|
+
{ label: 'Admin', value: 'Admin' },
|
|
197
|
+
{ label: 'User', value: 'User' },
|
|
198
|
+
],
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
]
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
## Export
|
|
207
|
+
|
|
208
|
+
- **Excel:** `exportTableToExcel(data, filename?, tableTitle?)` โ uses ExcelJS; suitable for larger files. NPM audit issues from transitive deps are addressed via `overrides` in package.json (`minimatch`).
|
|
209
|
+
- **CSV:** `exportTableToCSV(data, filename?)` โ plain string/Blob; no ExcelJS.
|
|
210
|
+
|
|
211
|
+
Both are available from the toolbar Data Export menu and as standalone imports.
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
## Exports
|
|
216
|
+
|
|
217
|
+
| Export | Description |
|
|
218
|
+
|--------|-------------|
|
|
219
|
+
| `SabReactTable` | Main grid component |
|
|
220
|
+
| `SabReactTableProps`, `LayoutMode`, `OnActionClickHandler` | Component and layout types |
|
|
221
|
+
| `DataFormatter`, `ActionFormatter` | Default cell and action formatters |
|
|
222
|
+
| `formatDateValue`, `renderDateCell`, `isIsoDateLike` | Date formatting helpers |
|
|
223
|
+
| `ActionIcons`, `ACTION_ICON_KEYS`, `TableAction`, `ActionConfig`, `ActionIconKey` | Action types and built-in icons |
|
|
224
|
+
| `exportTableToExcel`, `exportTableToCSV` | Standalone export helpers |
|
|
225
|
+
| `resizeColumnsByCellContent`, `getWidthInPixel`, `getWidthInPixelTitle` | Column resize utilities |
|
|
226
|
+
| `ColumnResizeDef`, `ResizeColumnsByCellContentParams` | Resize utility types |
|
|
227
|
+
| `DateFormatOptions` | Date format options type |
|
|
228
|
+
| `ColumnDef` | Re-exported from `@tanstack/react-table` |
|
|
229
|
+
|
|
230
|
+
---
|
|
231
|
+
|
|
232
|
+
## License
|
|
233
|
+
|
|
234
|
+
MIT
|