Vue Virtualized Table
The second version of implementation of vue-virtual-table
component, it was inspired from rc-table and ant-table, API design is 60%+ consistent. Or you could think I translated them from React to Vue and added virtualize scroll feature.
Features
- Support customize render
- Support virtualized scroll
- Support expand/collapse
- Support customize depth
Usage
Look the Demo or run this project example in Terminal with npm:
npm install
npm run serve
Code example:
import VirtualTable from 'vue-virtualized-table'
import 'vue-virtualized-table/src/table.css'
export default {
render() {
return (
<VirtualTable
row-key="id"
scroll={{ y: 200 }}
columns={columns}
data-source={dataSource}
/>
)
}
}
API
props
TableProps
{
rowClassName: {
type: [String, Function],
default: ''
},
tableLayout: {
type: String,
validator(val) {
return ['auto', 'fixed'].includes(val)
}
},
direction: {
type: String,
default: 'ltr',
validator(val) {
return ['ltr', 'rtl'].includes(val)
}
},
bordered: Boolean,
columns: {
type: Array,
required: true
},
components: {
type: Object,
default: () => TableComponents
},
dataSource: {
type: Array,
default: () => [],
required: true
},
expandable: Object,
useVirtual: Boolean,
rowHeight: Number,
scrollToRow: { type: Number, default: 0 },
prefixCls: {
type: String,
default: 'ant-table'
},
title: {
type: [Function, Object]
},
footer: {
type: [Function, Object]
},
rowKey: {
type: [String, Function],
required: true
},
rowSelection: Object,
scroll: {
type: Object,
default: () => ({})
},
showHeader: {
type: Boolean,
default: true
},
size: {
type: String,
default: 'default',
validator(val) {
return ['default', 'middle', 'small'].includes(val)
}
},
locale: {
type: Object,
default: () => DEFAULT_LOCALE
}
}
expandable
{
childrenColumnName: {
type: String,
default: 'children'
},
indentSize: {
type: Number,
default: 15
},
expandIcon: Function,
expandedRowRender: Function,
rowExpandable: Function,
expandedRowKeys: {
type: Array,
default: () => []
},
expandedDepth: {
type: Number,
default: null
},
defaultExpandAllRows: {
type: Boolean,
default: true
},
}
rowSelection
{
type: {
type: String,
default: 'radio',
validator(val) {
return ['radio', 'checkbox'].includes(val)
}
},
selectedRowKeys: {
type: Array,
default: () => []
},
onChange: {
type: Function,
default: (selectedRowKeys, selectedRows) => {}
},
onSelect: {
type: Function,
default: (record, selected, selectedRows, nativeEvent) => {}
}
}
ColumnProps
{
label: STRING_REQUIRED_PROP,
prop: STRING_REQUIRED_PROP,
key: STRING_REQUIRED_PROP,
width: [String, Number],
colspan: [Number, Function],
rowspan: [Number, Function],
className: [String, Function],
fixed: {
type: [Boolean, String],
validator(val) {
return [true, false, LEFT, RIGHT].includes(val)
}
},
align: {
type: String,
validator(val) {
return [LEFT, CENTER, RIGHT].includes(val)
}
},
ellipsis: BOOLEAN_FALSE_PROP,
expandable: BOOLEAN_FALSE_PROP,
render: Function,
renderHeader: Function,
resizable: BOOLEAN_FALSE_PROP
}
TableStore
isRowExpanded: (rowKey: string|RowModel) => boolean,
toggleRowExpansion: (rowKey: string|RowModel, state: boolean => void,
toggleExpandAll: (expand: boolean) => void,
toggleExpandDepth: (depth: number) => void,
isRowSelected: (rowKey: string|RowModel) => boolean,
toggleRowSelection: (rowKey: string|RowModel) =>
slots
empty | When no-data so show empty block |
title | The title panel slot |
footer | The footer panel slot |
events
select-change | (record: RowModel, selected: boolean, selectedRowKeys: string[], nativeEvent: Event) => void | When selection changed |
expand-change | (record: RowModel, isExpanded: boolean, expandedRowKeys: string[], nativeEvent: Event) => void | When trigger expand or collapse |
license
MIT