react-column-drag-resize-table 0.1.0 → 0.1.2
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 +36 -7
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -19,8 +19,6 @@ npm install react-column-drag-resize-table
|
|
|
19
19
|
|
|
20
20
|
Peers: **React** and **React DOM** ≥ **16.8**.
|
|
21
21
|
|
|
22
|
-
> If this name is unavailable on npm, publish as a [scoped package](https://docs.npmjs.com/about/scopes) (for example `@your-org/react-column-drag-resize-table`).
|
|
23
|
-
|
|
24
22
|
---
|
|
25
23
|
|
|
26
24
|
## How to use
|
|
@@ -61,13 +59,16 @@ export function Example() {
|
|
|
61
59
|
|
|
62
60
|
## Advanced example
|
|
63
61
|
|
|
64
|
-
Filtering, pagination,
|
|
62
|
+
Filtering, pagination, a **`renderSummary`** line, and **custom cells** with **`render`** (see [Column cells](#column-cells-accessor-and-render)):
|
|
65
63
|
|
|
66
64
|
```jsx
|
|
67
65
|
import { useMemo } from 'react';
|
|
68
66
|
import { DataTable } from 'react-column-drag-resize-table';
|
|
69
67
|
import 'react-column-drag-resize-table/styles.css';
|
|
70
68
|
|
|
69
|
+
const money = (n) =>
|
|
70
|
+
new Intl.NumberFormat(undefined, { style: 'currency', currency: 'USD' }).format(n);
|
|
71
|
+
|
|
71
72
|
const rows = [
|
|
72
73
|
{ id: 1, user_name: 'alice', amount: 100, status: 'ok' },
|
|
73
74
|
{ id: 2, user_name: 'bob', amount: 200, status: 'pending' }
|
|
@@ -78,8 +79,30 @@ export function AdvancedExample() {
|
|
|
78
79
|
() => [
|
|
79
80
|
{ id: 'id', title: 'ID', accessor: 'id' },
|
|
80
81
|
{ id: 'user_name', title: 'User', accessor: 'user_name' },
|
|
81
|
-
{
|
|
82
|
-
|
|
82
|
+
{
|
|
83
|
+
id: 'amount',
|
|
84
|
+
title: 'Amount',
|
|
85
|
+
accessor: 'amount',
|
|
86
|
+
render: (row) => money(row.amount)
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
id: 'status',
|
|
90
|
+
title: 'Status',
|
|
91
|
+
accessor: 'status',
|
|
92
|
+
render: (row) => (
|
|
93
|
+
<span
|
|
94
|
+
style={{
|
|
95
|
+
display: 'inline-block',
|
|
96
|
+
padding: '2px 8px',
|
|
97
|
+
borderRadius: 4,
|
|
98
|
+
fontSize: '0.875rem',
|
|
99
|
+
background: row.status === 'ok' ? '#e8f5e9' : '#fff3e0'
|
|
100
|
+
}}
|
|
101
|
+
>
|
|
102
|
+
{row.status}
|
|
103
|
+
</span>
|
|
104
|
+
)
|
|
105
|
+
}
|
|
83
106
|
],
|
|
84
107
|
[]
|
|
85
108
|
);
|
|
@@ -150,12 +173,18 @@ export function AdvancedExample() {
|
|
|
150
173
|
|
|
151
174
|
Used for each entry in **`columns`**.
|
|
152
175
|
|
|
176
|
+
#### Column cells: `accessor` and `render`
|
|
177
|
+
|
|
178
|
+
- **Plain value:** use a **string `accessor`** with the row field name (e.g. `accessor: 'user_name'`), or omit `accessor` and rely on **`id`** matching a key on the row (`row[id]`).
|
|
179
|
+
- **Custom content:** use **`render: (row) => …`** for formatting, badges, links, or any JSX. When **`render`** is set, it **replaces** the default cell value for that column (string `accessor` is then only documentary for you; it is not used for display).
|
|
180
|
+
- A **function `accessor`** is still accepted for custom cells, but **`render`** is the preferred API for that so the column definition stays clear: *field key vs cell UI*.
|
|
181
|
+
|
|
153
182
|
| Property | Required | Type | Default | Possible values / notes | Description |
|
|
154
183
|
|----------|----------|------|---------|-------------------------|-------------|
|
|
155
184
|
| `id` | **yes** | `string` | — | Unique among columns | Stable id (order, resize, filters, storage). |
|
|
156
185
|
| `title` | **yes** | `string` | — | — | Header label. |
|
|
157
|
-
| `accessor` | no | `keyof T \| ((row: T) => ReactNode)` | — | — |
|
|
158
|
-
| `render` | no | `(row: T) => ReactNode` | — | — |
|
|
186
|
+
| `accessor` | no | `keyof T \| ((row: T) => ReactNode)` | — | — | Row field key for simple columns, or legacy function form; see [above](#column-cells-accessor-and-render). If omitted, cell value defaults to `row[id]`. |
|
|
187
|
+
| `render` | no | `(row: T) => ReactNode` | — | — | Custom cell; if set, used instead of the value from string `accessor` / `row[id]`. |
|
|
159
188
|
|
|
160
189
|
### `FilterField`
|
|
161
190
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-column-drag-resize-table",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "React data table component: draggable column reorder, resizable columns, text filters, pagination, optional localStorage column layout, CSS variables theming. For admin dashboards and internal tools.",
|
|
5
5
|
"author": "Armine Inants",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
},
|
|
19
19
|
"files": [
|
|
20
20
|
"dist",
|
|
21
|
-
"README.md"
|
|
21
|
+
"README.md",
|
|
22
|
+
"LICENSE"
|
|
22
23
|
],
|
|
23
24
|
"sideEffects": [
|
|
24
25
|
"**/*.css"
|