@yester/virtual-table 1.1.0 → 1.1.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/README.md +76 -7
- package/dist/types/index.d.ts +1 -0
- package/dist/virtual-table.es.js +889 -879
- package/dist/virtual-table.es.js.map +1 -1
- package/dist/virtual-table.umd.js +14 -14
- package/dist/virtual-table.umd.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -127,22 +127,91 @@ const detailFields = {
|
|
|
127
127
|
|
|
128
128
|
```typescript
|
|
129
129
|
interface PivotFields {
|
|
130
|
-
rows:
|
|
131
|
-
columns:
|
|
132
|
-
values:
|
|
130
|
+
rows: DimensionNode[]; // Row dimensions
|
|
131
|
+
columns: DimensionNode[]; // Column dimensions
|
|
132
|
+
values: MetricNode[]; // Value fields (metrics)
|
|
133
133
|
}
|
|
134
134
|
```
|
|
135
135
|
|
|
136
|
-
###
|
|
136
|
+
### Field Configuration
|
|
137
|
+
|
|
138
|
+
#### DimensionNode (Rows & Columns)
|
|
137
139
|
|
|
138
140
|
| Property | Type | Description |
|
|
139
141
|
|----------|------|-------------|
|
|
140
142
|
| `field` | `string` | Data field key |
|
|
141
|
-
| `title` | `
|
|
143
|
+
| `title` | `string` | Column header title |
|
|
142
144
|
| `width` | `number \| string` | Column width |
|
|
143
|
-
| `
|
|
144
|
-
| `
|
|
145
|
+
| `total` | `{ enabled: boolean; label?: string }` | Subtotal configuration |
|
|
146
|
+
| `collapsed` | `boolean` | Whether the dimension is collapsed by default |
|
|
147
|
+
| `sort` | `{ enabled: boolean; type: 'asc' \| 'desc' }` | Sort configuration |
|
|
148
|
+
|
|
149
|
+
#### MetricNode (Values)
|
|
150
|
+
|
|
151
|
+
| Property | Type | Description |
|
|
152
|
+
|----------|------|-------------|
|
|
153
|
+
| `field` | `string` | Data field key or unique key for expression |
|
|
154
|
+
| `title` | `string` | Header title |
|
|
155
|
+
| `width` | `number \| string` | Column width |
|
|
156
|
+
| `calculateType` | `'sum' \| 'avg' \| 'count' \| 'min' \| 'max' \| 'd_count' \| 'expr'` | Aggregation type |
|
|
157
|
+
| `expression` | `string` | Expression for calculation (e.g. `'{amount} * {price}'`) |
|
|
158
|
+
| `formatter` | `(val: any, record: any) => ReactNode` | Cell content formatter |
|
|
145
159
|
| `emptyReplace` | `string` | Replacement for empty values |
|
|
160
|
+
| `hidden` | `boolean` | Whether to hide this metric column |
|
|
161
|
+
|
|
162
|
+
## Advanced Usage
|
|
163
|
+
|
|
164
|
+
### Calculated Fields
|
|
165
|
+
|
|
166
|
+
You can define a new metric based on other metrics using `calculateType: 'expr'` and `expression`. Variables in `{}` refer to other metric fields.
|
|
167
|
+
|
|
168
|
+
```tsx
|
|
169
|
+
values: [
|
|
170
|
+
{ field: 'amount', title: 'Amount', calculateType: 'sum' },
|
|
171
|
+
{ field: 'price', title: 'Price', calculateType: 'avg' },
|
|
172
|
+
{
|
|
173
|
+
field: 'total_value',
|
|
174
|
+
title: 'Total Value',
|
|
175
|
+
calculateType: 'expr',
|
|
176
|
+
expression: '{amount} * {price}'
|
|
177
|
+
}
|
|
178
|
+
]
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Cell Formatting
|
|
182
|
+
|
|
183
|
+
Use `formatter` to customize cell rendering, such as adding currency symbols or returning React components.
|
|
184
|
+
|
|
185
|
+
```tsx
|
|
186
|
+
values: [
|
|
187
|
+
{
|
|
188
|
+
field: 'price',
|
|
189
|
+
title: 'Price',
|
|
190
|
+
formatter: (val) => <span style={{ color: 'red' }}>¥{val}</span>
|
|
191
|
+
}
|
|
192
|
+
]
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Nested Column Headers
|
|
196
|
+
|
|
197
|
+
Simply add multiple dimensions to `columns` in `PivotFields` to create nested headers.
|
|
198
|
+
|
|
199
|
+
```tsx
|
|
200
|
+
columns: [
|
|
201
|
+
{ field: 'year', title: 'Year', width: 100 }, // Top level
|
|
202
|
+
{ field: 'quarter', title: 'Quarter', width: 100 } // Sub level
|
|
203
|
+
]
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Default Collapsed State
|
|
207
|
+
|
|
208
|
+
Set `collapsed: true` on a row dimension to collapse it by default.
|
|
209
|
+
|
|
210
|
+
```tsx
|
|
211
|
+
rows: [
|
|
212
|
+
{ field: 'province', title: 'Province', collapsed: true }
|
|
213
|
+
]
|
|
214
|
+
```
|
|
146
215
|
|
|
147
216
|
## Development
|
|
148
217
|
|