react-column-drag-resize-table 0.1.1 → 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.
Files changed (2) hide show
  1. package/README.md +36 -5
  2. package/package.json +3 -2
package/README.md CHANGED
@@ -59,13 +59,16 @@ export function Example() {
59
59
 
60
60
  ## Advanced example
61
61
 
62
- Filtering, pagination, and a **`renderSummary`** line using the built-in filter bar:
62
+ Filtering, pagination, a **`renderSummary`** line, and **custom cells** with **`render`** (see [Column cells](#column-cells-accessor-and-render)):
63
63
 
64
64
  ```jsx
65
65
  import { useMemo } from 'react';
66
66
  import { DataTable } from 'react-column-drag-resize-table';
67
67
  import 'react-column-drag-resize-table/styles.css';
68
68
 
69
+ const money = (n) =>
70
+ new Intl.NumberFormat(undefined, { style: 'currency', currency: 'USD' }).format(n);
71
+
69
72
  const rows = [
70
73
  { id: 1, user_name: 'alice', amount: 100, status: 'ok' },
71
74
  { id: 2, user_name: 'bob', amount: 200, status: 'pending' }
@@ -76,8 +79,30 @@ export function AdvancedExample() {
76
79
  () => [
77
80
  { id: 'id', title: 'ID', accessor: 'id' },
78
81
  { id: 'user_name', title: 'User', accessor: 'user_name' },
79
- { id: 'amount', title: 'Amount', accessor: 'amount' },
80
- { id: 'status', title: 'Status', accessor: 'status' }
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
+ }
81
106
  ],
82
107
  []
83
108
  );
@@ -148,12 +173,18 @@ export function AdvancedExample() {
148
173
 
149
174
  Used for each entry in **`columns`**.
150
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
+
151
182
  | Property | Required | Type | Default | Possible values / notes | Description |
152
183
  |----------|----------|------|---------|-------------------------|-------------|
153
184
  | `id` | **yes** | `string` | — | Unique among columns | Stable id (order, resize, filters, storage). |
154
185
  | `title` | **yes** | `string` | — | — | Header label. |
155
- | `accessor` | no | `keyof T \| ((row: T) => ReactNode)` | — | — | Key on the row, or function returning cell content. If omitted, falls back to `row[id]`. |
156
- | `render` | no | `(row: T) => ReactNode` | — | — | If set, used for the cell instead of `accessor`. |
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]`. |
157
188
 
158
189
  ### `FilterField`
159
190
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-column-drag-resize-table",
3
- "version": "0.1.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"