Skip to content

Commit 518e233

Browse files
committed
feat: Udpate vue-virtualized-table to V2
1 parent 1d67d3e commit 518e233

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+9638
-0
lines changed

README.md

Lines changed: 283 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,283 @@
1+
# Vue Virtualized Table
2+
3+
The second version of implementation of `vue-virtual-table` component, it was inspired from [rc-table](https://github.com/react-component/table) and [ant-table](https://ant.design/components/table), API design is 60%+ consistent. Or you could think I translated them from React to Vue and added *virtualize scroll* feature.
4+
5+
## Features
6+
1. Support **customize render**
7+
2. Support **virtualized scroll**
8+
3. Support **expand/collapse**
9+
4. Support **customize depth**
10+
11+
## Usage
12+
[CodeSandBox demo](https://codesandbox.io/s/vue-resize-observer-vzk4g) or run this project example in Terminal with npm:
13+
14+
```bash
15+
npm install
16+
npm run serve
17+
```
18+
19+
Code example:
20+
```js
21+
import VirtualTable from 'vue-virtualized-table'
22+
import 'vue-virtualized-table/src/table.css'
23+
24+
export default {
25+
render() {
26+
return (
27+
<VirtualTable
28+
row-key="id"
29+
scroll={{ y: 200 }}
30+
columns={columns}
31+
data-source={dataSource}
32+
/>
33+
)
34+
}
35+
}
36+
```
37+
38+
## API
39+
40+
### props
41+
42+
#### TableProps
43+
```js
44+
{
45+
rowClassName: {
46+
type: [String, Function],
47+
default: ''
48+
},
49+
50+
// fixed when header/columns are fixed, or using column.ellipsis
51+
tableLayout: {
52+
type: String,
53+
validator(val) {
54+
return ['auto', 'fixed'].includes(val)
55+
}
56+
},
57+
58+
direction: {
59+
type: String,
60+
default: 'ltr',
61+
validator(val) {
62+
return ['ltr', 'rtl'].includes(val)
63+
}
64+
},
65+
66+
// Whether to show all table borders
67+
bordered: Boolean,
68+
69+
// Columns of table: ColumnProps[]
70+
columns: {
71+
type: Array,
72+
required: true
73+
},
74+
75+
// Override default table elements
76+
components: {
77+
type: Object,
78+
default: () => TableComponents
79+
},
80+
81+
// Data record array to be displayed
82+
dataSource: {
83+
type: Array,
84+
default: () => [],
85+
required: true
86+
},
87+
88+
// expandable
89+
expandable: Object, // See it below
90+
// Whether to use virtualize scroll behavior
91+
useVirtual: Boolean,
92+
// The row height number of per row in TableBody
93+
rowHeight: Number,
94+
// The row index to specify where the view scroll to
95+
scrollToRow: { type: Number, default: 0 },
96+
97+
prefixCls: {
98+
type: String,
99+
default: 'ant-table'
100+
},
101+
102+
// Table footer renderer
103+
// Should it be slot?
104+
title: {
105+
type: [Function, Object]
106+
},
107+
108+
// Table footer renderer
109+
// Should it be slot?
110+
footer: {
111+
type: [Function, Object]
112+
},
113+
114+
rowKey: {
115+
type: [String, Function],
116+
required: true
117+
},
118+
119+
rowSelection: Object,
120+
121+
// { x: number | true, y: number }
122+
// x: Set horizontal scrolling, can also be used to specify the width of the scroll area, could be number, percent value, true and 'max-content' number | true -
123+
// y: Set vertical scrolling, can also be used to specify the height of the scroll area, could be number number -
124+
scroll: {
125+
type: Object,
126+
default: () => ({})
127+
},
128+
129+
showHeader: {
130+
type: Boolean,
131+
default: true
132+
},
133+
134+
size: {
135+
type: String,
136+
default: 'default',
137+
validator(val) {
138+
return ['default', 'middle', 'small'].includes(val)
139+
}
140+
},
141+
142+
locale: {
143+
type: Object,
144+
default: () => DEFAULT_LOCALE
145+
}
146+
}
147+
```
148+
149+
#### expandable
150+
```js
151+
{
152+
// The children's name
153+
childrenColumnName: {
154+
type: String,
155+
default: 'children' // string
156+
},
157+
158+
// Indent size in pixels of tree data
159+
indentSize: {
160+
type: Number,
161+
default: 15 // must be Number
162+
},
163+
164+
// Customize row expand Icon. Ref example
165+
expandIcon: Function, // (h, { prefixCls: string, expanded: boolean, expandable: boolean, record: object, onExpand: Function }) => VNode,
166+
167+
// Customize row expand render.
168+
expandedRowRender: Function, // (h, { record: object, index: number, index: number, expanded: boolean }) => VNode,
169+
170+
// Whether row can be expandable or not
171+
rowExpandable: Function, // (h) => boolean,
172+
173+
// Current expanded row keys
174+
expandedRowKeys: {
175+
type: Array,
176+
default: () => [] // RowKey[]
177+
},
178+
179+
// Current expanded deep into which depth
180+
expandedDepth: {
181+
type: Number,
182+
default: null // RowKey[]
183+
},
184+
185+
// Expand all rows initially
186+
defaultExpandAllRows: {
187+
type: Boolean,
188+
default: true // boolean
189+
},
190+
}
191+
```
192+
193+
#### rowSelection
194+
```js
195+
{
196+
type: {
197+
type: String,
198+
default: 'radio',
199+
validator(val) {
200+
return ['radio', 'checkbox'].includes(val)
201+
}
202+
},
203+
// Controlled selected row keys: string[]|number[]
204+
selectedRowKeys: {
205+
type: Array,
206+
default: () => []
207+
},
208+
// Callback executed when selected rows change
209+
onChange: {
210+
type: Function,
211+
default: (selectedRowKeys, selectedRows) => {}
212+
},
213+
// Callback executed when select/deselect one row
214+
onSelect: {
215+
type: Function,
216+
default: (record, selected, selectedRows, nativeEvent) => {}
217+
}
218+
}
219+
```
220+
221+
#### ColumnProps
222+
```js
223+
{
224+
label: STRING_REQUIRED_PROP,
225+
prop: STRING_REQUIRED_PROP,
226+
key: STRING_REQUIRED_PROP,
227+
width: [String, Number],
228+
229+
colspan: [Number, Function],
230+
rowspan: [Number, Function],
231+
className: [String, Function],
232+
233+
fixed: {
234+
type: [Boolean, String],
235+
validator(val) {
236+
return [true, false, LEFT, RIGHT].includes(val)
237+
}
238+
},
239+
240+
align: {
241+
type: String,
242+
validator(val) {
243+
return [LEFT, CENTER, RIGHT].includes(val)
244+
}
245+
},
246+
247+
ellipsis: BOOLEAN_FALSE_PROP,
248+
expandable: BOOLEAN_FALSE_PROP,
249+
250+
render: Function, // BodyRowCell Render: VNode|({ store: TableStore, row: RowModel, column: ColumnConfig }) => VNode
251+
renderHeader: Function, // HeaderRowCell Render: VNode|({ store, row, column }) => VNode
252+
253+
// TODO
254+
resizable: BOOLEAN_FALSE_PROP
255+
}
256+
```
257+
258+
### TableStore
259+
```js
260+
isRowExpanded: (rowKey: string|RowModel) => boolean, // Whether current row/rowKey is expanded or not
261+
toggleRowExpansion: (rowKey: string|RowModel, state: boolean => void, // To toggle current expansion state
262+
toggleExpandAll: (expand: boolean) => void,// To toggle all rows be expanded
263+
toggleExpandDepth: (depth: number) => void, // To toggle rows be expanded by specified depth number
264+
isRowSelected: (rowKey: string|RowModel) => boolean, // Whether current row/rowKey is selected or not
265+
toggleRowSelection: (rowKey: string|RowModel) => // To toggle current row selection state
266+
```
267+
268+
### slots
269+
270+
|name|render|
271+
|:--|:--|
272+
|`empty`| When no-data so show empty block |
273+
|`title`| The title panel slot |
274+
|`footer`| The footer panel slot |
275+
276+
### events
277+
|name|parameters|description|
278+
|:--|:--|:--|
279+
| select-change | `(record: RowModel, selected: boolean, selectedRowKeys: string[], nativeEvent: Event) => void` | When selection changed |
280+
| expand-change | `(record: RowModel, isExpanded: boolean, expandedRowKeys: string[], nativeEvent: Event) => void` | When trigger expand or collapse|
281+
282+
## license
283+
MIT

0 commit comments

Comments
 (0)