jc-react-datatable 1.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 +198 -0
- package/dist/jc-react-datatable.es.js +1651 -0
- package/dist/jc-react-datatable.umd.js +51 -0
- package/dist/style.css +1 -0
- package/package.json +46 -0
package/README.md
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
# JC React DataTable
|
|
2
|
+
|
|
3
|
+
A modern, highly customizable, and performance-optimized React DataTable library. Built with pure JavaScript (ES6+) and React Hooks, offering a robust set of features with zero external logic dependencies.
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
## ✨ Features
|
|
10
|
+
|
|
11
|
+
- **🚀 High Performance**: Optimized with `useMemo` and `useCallback` for efficient rendering.
|
|
12
|
+
- **🔍 Advanced Filtering**: Column-specific search with support for custom filter functions.
|
|
13
|
+
- **⇅ Sorting**: Multi-type sorting (String, Number, Date, Custom).
|
|
14
|
+
- **📄 Pagination**: Built-in client-side pagination with customizable page sizes.
|
|
15
|
+
- **📱 Responsive Design**:
|
|
16
|
+
- Auto-enables horizontal scrolling on small screens.
|
|
17
|
+
- Smart column filter positioning (prevents overflow on edge columns).
|
|
18
|
+
- Mobile-friendly layout.
|
|
19
|
+
- **🎨 Modern UI**:
|
|
20
|
+
- Clean, sticky headers.
|
|
21
|
+
- Hover effects and polished aesthetics.
|
|
22
|
+
- Toggleable filter inputs via icons (keeps UI clean).
|
|
23
|
+
- **↕️ Scrollable Body**: Optional `maxHeight` prop for fixed-header scrolling tables.
|
|
24
|
+
- **📦 Zero Heavy Deps**: Only React and PropTypes.
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## 📦 Installation
|
|
29
|
+
|
|
30
|
+
Install the package via npm:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npm install jc-react-datatable
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## 🚀 Usage
|
|
39
|
+
|
|
40
|
+
### 1. Import Component & Styles
|
|
41
|
+
|
|
42
|
+
```jsx
|
|
43
|
+
import { DataTable } from 'jc-react-datatable';
|
|
44
|
+
import 'jc-react-datatable/dist/style.css'; // Import default styles
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### 2. Define Columns & Data
|
|
48
|
+
|
|
49
|
+
```jsx
|
|
50
|
+
const columns = [
|
|
51
|
+
{
|
|
52
|
+
key: 'id',
|
|
53
|
+
header: 'ID',
|
|
54
|
+
width: '60px',
|
|
55
|
+
sortable: true
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
key: 'name',
|
|
59
|
+
header: 'Name',
|
|
60
|
+
sortable: true,
|
|
61
|
+
searchable: true
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
key: 'role',
|
|
65
|
+
header: 'Role',
|
|
66
|
+
sortable: true,
|
|
67
|
+
searchable: true
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
key: 'joined',
|
|
71
|
+
header: 'Joined Date',
|
|
72
|
+
sortable: true,
|
|
73
|
+
render: (row) => new Date(row.joined).toLocaleDateString()
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
key: 'actions',
|
|
77
|
+
header: 'Actions',
|
|
78
|
+
render: (row) => <button onClick={() => alert(row.name)}>Edit</button>
|
|
79
|
+
}
|
|
80
|
+
];
|
|
81
|
+
|
|
82
|
+
const data = [
|
|
83
|
+
{ id: 1, name: 'John Doe', role: 'Admin', joined: '2023-01-15' },
|
|
84
|
+
{ id: 2, name: 'Jane Smith', role: 'User', joined: '2023-02-20' },
|
|
85
|
+
// ... more data
|
|
86
|
+
];
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### 3. Render the Table
|
|
90
|
+
|
|
91
|
+
```jsx
|
|
92
|
+
function App() {
|
|
93
|
+
return (
|
|
94
|
+
<div style={{ padding: '20px' }}>
|
|
95
|
+
<h1>User Directory</h1>
|
|
96
|
+
|
|
97
|
+
<DataTable
|
|
98
|
+
columns={columns}
|
|
99
|
+
data={data}
|
|
100
|
+
pagination={true}
|
|
101
|
+
pageSizeOptions={[5, 10, 20]}
|
|
102
|
+
defaultPageSize={10}
|
|
103
|
+
onRowClick={(row) => console.log('Clicked Row:', row)}
|
|
104
|
+
maxHeight="400px" // Enable vertical scroll
|
|
105
|
+
loading={false}
|
|
106
|
+
/>
|
|
107
|
+
</div>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## 📖 API Reference
|
|
115
|
+
|
|
116
|
+
### `DataTable` Props
|
|
117
|
+
|
|
118
|
+
| Prop | Type | Default | Description |
|
|
119
|
+
|------|------|---------|-------------|
|
|
120
|
+
| `columns` | `Array` | **Required** | Array of column definitions (see below). |
|
|
121
|
+
| `data` | `Array` | **Required** | Array of data objects to display. |
|
|
122
|
+
| `pagination` | `Boolean` | `true` | Enable/Disable pagination. |
|
|
123
|
+
| `pageSizeOptions` | `Array` | `[5, 10, 20, 50]` | Dropdown options for "Rows per page". |
|
|
124
|
+
| `defaultPageSize` | `Number` | `10` | Initial number of rows per page. |
|
|
125
|
+
| `onRowClick` | `Function` | `undefined` | Callback function when a row is clicked: `(row) => {}`. |
|
|
126
|
+
| `loading` | `Boolean` | `false` | Shows a loading spinner if true. |
|
|
127
|
+
| `noDataText` | `String` | `'No records found'` | Custom message when data is empty/filtered out. |
|
|
128
|
+
| `maxHeight` | `String` | `undefined` | Sets a fixed height (e.g., `"300px"`). Enables vertical scrolling with **sticky headers**. |
|
|
129
|
+
| `className` | `String` | `''` | Extra CSS class for the wrapper div. |
|
|
130
|
+
|
|
131
|
+
### `Column` Definition Object
|
|
132
|
+
|
|
133
|
+
| Property | Type | Description |
|
|
134
|
+
|----------|------|-------------|
|
|
135
|
+
| `key` | `String` | **Required**. Unique key corresponding to the field in the data object. |
|
|
136
|
+
| `header` | `String` | **Required**. The text to display in the table header. |
|
|
137
|
+
| `width` | `String` | Optional. CSS width (e.g., `"150px"`, `"20%"`). |
|
|
138
|
+
| `sortable` | `Boolean` | Enable sorting for this column. |
|
|
139
|
+
| `searchable` | `Boolean` | Enable text filtering (search) for this column. |
|
|
140
|
+
| `render` | `Function` | Custom cell renderer: `(row, index) => ReactNode`. |
|
|
141
|
+
| `sortFn` | `Function` | Custom sort logic: `(a, b) => number` (-1, 0, 1). |
|
|
142
|
+
| `filterFn` | `Function` | Custom filter logic: `(value, filterText, row) => boolean`. |
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## 🛠 customization
|
|
147
|
+
|
|
148
|
+
### CSS Overrides
|
|
149
|
+
The library allows easy styling overrides via standard CSS.
|
|
150
|
+
|
|
151
|
+
```css
|
|
152
|
+
/* Example: Dark Header */
|
|
153
|
+
.jc-datatable-th {
|
|
154
|
+
background-color: #2d3748;
|
|
155
|
+
color: #ffffff;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/* Example: Row Hover Color */
|
|
159
|
+
.jc-datatable-tr:hover {
|
|
160
|
+
background-color: #ebf8ff;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/* Example: Active Page Button */
|
|
164
|
+
.jc-datatable-pagination-btn:not(:disabled):hover {
|
|
165
|
+
border-color: #3182ce;
|
|
166
|
+
color: #3182ce;
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
## 💻 Development
|
|
173
|
+
|
|
174
|
+
Clone the repository and run locally:
|
|
175
|
+
|
|
176
|
+
1. **Install Dependencies**
|
|
177
|
+
```bash
|
|
178
|
+
npm install
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
2. **Start Dev Server** (Demo App)
|
|
182
|
+
```bash
|
|
183
|
+
npm run dev
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
3. **Build Library**
|
|
187
|
+
```bash
|
|
188
|
+
npm run build
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
## 📄 License
|
|
194
|
+
|
|
195
|
+
MIT © [Jay Patel](https://github.com/jaypatel)
|
|
196
|
+
|
|
197
|
+
---
|
|
198
|
+
*Built with ❤️ using React*.
|