@yester/virtual-table 1.0.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/style.css +1 -1
- package/dist/types/index.d.ts +27 -18
- package/dist/utils/dataHandler.d.ts +8 -15
- package/dist/virtual-table.es.js +1404 -1337
- 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 +5 -2
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
|
|
package/dist/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.virtual-table .virtual-table-container:before,.virtual-table .virtual-table-container:after{display:none}.virtual-table,.virtual-table .virtual-table{--virtual-table-scrollbar-width: 0px !important}.virtual-table table{table-layout:fixed!important;width:100%!important;border-spacing:0}.virtual-table .virtual-table-header th.virtual-table-cell{background:#fafafa;border-bottom:1px solid #e8e8e8;font-weight:500;padding:10px 16px;border-right:1px solid #e8e8e8;white-space:nowrap;text-overflow:ellipsis;overflow:hidden}.virtual-table .virtual-table-thead>tr:first-child>th{border-top:1px solid #e8e8e8}.virtual-table .virtual-table-thead>tr>th:first-child{border-left:1px solid #e8e8e8}.virtual-table .virtual-table-thead>tr:not(:last-child)>th[colspan]{border-bottom:1px solid #e8e8e8}.virtual-table-cell{box-sizing:border-box;padding:10px 16px;line-height:1.5;border-bottom:1px solid #e8e8e8;background:#fff}[data-theme=dark] .virtual-table-cell{box-sizing:border-box;line-height:1.5;padding:10px 16px;border-bottom:1px solid #303030;background:#141414}[data-theme=dark] .virtual-table .virtual-table-header th.virtual-table-cell{background:#1d1d1d;border-bottom:1px solid #303030;border-right:1px solid #303030}[data-theme=dark] .virtual-table .virtual-table-thead>tr:not(:last-child)>th[colspan]{border-bottom:1px solid #303030}.expand-icon{cursor:pointer;color:var(--primary-color);margin-right:4px;line-height:0}.hide-scrollbar{-ms-overflow-style:none;scrollbar-width:none}.hide-scrollbar::-webkit-scrollbar{display:none}
|
|
1
|
+
.virtual-table .virtual-table-container:before,.virtual-table .virtual-table-container:after{display:none}.virtual-table,.virtual-table .virtual-table{--virtual-table-scrollbar-width: 0px !important}.virtual-table table{table-layout:fixed!important;width:100%!important;border-spacing:0}.virtual-table .virtual-table-header th.virtual-table-cell{background:#fafafa;border-bottom:1px solid #e8e8e8;font-weight:500;padding:10px 16px;border-right:1px solid #e8e8e8;white-space:nowrap;text-overflow:ellipsis;overflow:hidden}.virtual-table .virtual-table-thead>tr:first-child>th{border-top:1px solid #e8e8e8}.virtual-table .virtual-table-thead>tr>th:first-child{border-left:1px solid #e8e8e8}.virtual-table .virtual-table-thead>tr:not(:last-child)>th[colspan]{border-bottom:1px solid #e8e8e8}.virtual-table-cell{box-sizing:border-box;padding:10px 16px;line-height:1.5;border-bottom:1px solid #e8e8e8;background:#fff}[data-theme=dark] .virtual-table-cell{box-sizing:border-box;line-height:1.5;padding:10px 16px;border-bottom:1px solid #303030;background:#141414}[data-theme=dark] .virtual-table .virtual-table-header th.virtual-table-cell{background:#1d1d1d;border-bottom:1px solid #303030;border-right:1px solid #303030}[data-theme=dark] .virtual-table .virtual-table-thead>tr:not(:last-child)>th[colspan]{border-bottom:1px solid #303030}.expand-icon{cursor:pointer;color:var(--primary-color);margin-right:4px;line-height:0}.virtual-table-cell-link{cursor:pointer;text-decoration:none;color:var(--primary-color)}.virtual-table-cell-link:hover{color:var(--primary-color-hover)}.hide-scrollbar{-ms-overflow-style:none;scrollbar-width:none}.hide-scrollbar::-webkit-scrollbar{display:none}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
2
|
|
|
3
|
-
export interface
|
|
3
|
+
export interface BaseNode {
|
|
4
4
|
/**
|
|
5
5
|
* 字段唯一标识
|
|
6
6
|
*/
|
|
@@ -9,38 +9,47 @@ export interface CustomTreeNode {
|
|
|
9
9
|
* 标题
|
|
10
10
|
*/
|
|
11
11
|
title?: string;
|
|
12
|
-
/**
|
|
13
|
-
* 是否收起(默认都展开)
|
|
14
|
-
* @description 优先级 `collapseFields` > `expandDepth` > `collapseAll` > `collapsed`
|
|
15
|
-
*/
|
|
16
|
-
collapsed?: boolean;
|
|
17
12
|
/**
|
|
18
13
|
* 字段描述
|
|
19
14
|
*/
|
|
20
15
|
description?: string;
|
|
16
|
+
width?: number | string;
|
|
17
|
+
style?: React.CSSProperties;
|
|
18
|
+
fixed?: boolean | string;
|
|
19
|
+
colSpan?: number;
|
|
20
|
+
dataIndex?: string;
|
|
21
|
+
hidden?: boolean;
|
|
22
|
+
key?: string;
|
|
23
|
+
children?: BaseNode[];
|
|
24
|
+
}
|
|
25
|
+
export interface DimensionNode extends BaseNode {
|
|
21
26
|
/**
|
|
22
|
-
*
|
|
27
|
+
* 是否收起(默认都展开)
|
|
28
|
+
* @description 优先级 `collapseFields` > `expandDepth` > `collapseAll` > `collapsed`
|
|
23
29
|
*/
|
|
24
|
-
|
|
25
|
-
width?: number | string;
|
|
30
|
+
collapsed?: boolean;
|
|
26
31
|
total?: {
|
|
27
32
|
enabled: boolean;
|
|
28
33
|
label?: string;
|
|
29
34
|
position?: 'top' | 'bottom';
|
|
30
35
|
};
|
|
31
|
-
emptyReplace?: string;
|
|
32
|
-
calculateType?: 'sum' | 'avg' | 'count' | 'min' | 'max' | 'd_count' | 'variance' | 'stddev';
|
|
33
36
|
sort?: {
|
|
34
37
|
enabled: boolean;
|
|
35
38
|
type: 'asc' | 'desc';
|
|
36
39
|
};
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
clickExpandChildren?: boolean;
|
|
41
|
+
children?: DimensionNode[];
|
|
42
|
+
}
|
|
43
|
+
export interface MetricNode extends BaseNode {
|
|
44
|
+
emptyReplace?: string;
|
|
45
|
+
calculateType?: 'sum' | 'avg' | 'count' | 'min' | 'max' | 'd_count' | 'variance' | 'stddev' | 'expr';
|
|
46
|
+
expression?: string;
|
|
41
47
|
render?: (val: any, record: any, index: number) => React.ReactNode;
|
|
48
|
+
formatter?: (val: any, record: any) => React.ReactNode;
|
|
42
49
|
type?: string;
|
|
50
|
+
children?: MetricNode[];
|
|
43
51
|
}
|
|
52
|
+
export type CustomTreeNode = DimensionNode | MetricNode;
|
|
44
53
|
export interface DataCell {
|
|
45
54
|
content: string | number | null | undefined;
|
|
46
55
|
rowspan: number;
|
|
@@ -68,9 +77,9 @@ export interface SortParam {
|
|
|
68
77
|
sortType: 'asc' | 'desc';
|
|
69
78
|
}
|
|
70
79
|
export interface PivotFields {
|
|
71
|
-
rows:
|
|
72
|
-
columns:
|
|
73
|
-
values:
|
|
80
|
+
rows: DimensionNode[];
|
|
81
|
+
columns: DimensionNode[];
|
|
82
|
+
values: MetricNode[];
|
|
74
83
|
}
|
|
75
84
|
export interface PivotParams {
|
|
76
85
|
data: any[];
|
|
@@ -21,27 +21,20 @@ export declare const dataHandler: (params: PivotParams) => {
|
|
|
21
21
|
tableColumns: {
|
|
22
22
|
width: string | number;
|
|
23
23
|
key: string;
|
|
24
|
+
emptyReplace?: string;
|
|
25
|
+
calculateType?: "sum" | "avg" | "count" | "min" | "max" | "d_count" | "variance" | "stddev" | "expr";
|
|
26
|
+
expression?: string;
|
|
27
|
+
render?: (val: any, record: any, index: number) => React.ReactNode;
|
|
28
|
+
formatter?: (val: any, record: any) => React.ReactNode;
|
|
29
|
+
type?: string;
|
|
30
|
+
children?: import('../types').MetricNode[];
|
|
24
31
|
field: string;
|
|
25
32
|
title?: string;
|
|
26
|
-
collapsed?: boolean;
|
|
27
33
|
description?: string;
|
|
28
|
-
children?: import('../types').CustomTreeNode[];
|
|
29
|
-
total?: {
|
|
30
|
-
enabled: boolean;
|
|
31
|
-
label?: string;
|
|
32
|
-
position?: "top" | "bottom";
|
|
33
|
-
};
|
|
34
|
-
emptyReplace?: string;
|
|
35
|
-
calculateType?: "sum" | "avg" | "count" | "min" | "max" | "d_count" | "variance" | "stddev";
|
|
36
|
-
sort?: {
|
|
37
|
-
enabled: boolean;
|
|
38
|
-
type: "asc" | "desc";
|
|
39
|
-
};
|
|
40
34
|
style?: React.CSSProperties;
|
|
41
35
|
fixed?: boolean | string;
|
|
42
36
|
colSpan?: number;
|
|
43
37
|
dataIndex?: string;
|
|
44
|
-
|
|
45
|
-
type?: string;
|
|
38
|
+
hidden?: boolean;
|
|
46
39
|
}[];
|
|
47
40
|
};
|