2.2.2 • Published 6 years ago

element-table v2.2.2

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

element-table

A element-table component for Vue.js.

Demo

http://element-component.github.io/element-table

Installation

npm i element-table -D

Usage

import Vue from 'vue'
import ElTable from 'element-table'
import 'element-theme-chalk'

Vue.use(ElTable)

or

import Vue from 'vue'
import { ElTable } from 'element-table'
import { ElTableColumn } from 'element-table'

Vue.component('el-table', ElTable)
Vue.component('el-table-column', ElTableColumn)

Table Attributes

参数说明类型可选值默认值
data显示的数据array
heightTable 的高度,默认为自动高度。如果 height 为 number 类型,单位 px;如果 height 为 string 类型,则 Table 的高度受控于外部样式。string/number
stripe是否为斑马纹 tablebooleanfalse
border是否带有纵向边框booleanfalse
fit列的宽度是否自撑开booleantrue
show-header是否显示表头boolean-true
highlight-current-row是否要高亮当前行booleanfalse
row-class-name行的 className 的回调方法,也可以使用字符串为所有行设置一个固定的 className。Function(row, index)/String
row-style行的 style 的回调方法,也可以使用一个固定的 Object 为所有行设置一样的 Style。Function(row, index)/Object
row-key行数据的 Key,用来优化 Table 的渲染;在使用 reserve-selection 功能的情况下,该属性是必填的Function(row)/String

Table Events

事件名说明参数
select当用户手动勾选数据行的 Checkbox 时触发的事件selection, row
select-all当用户手动勾选全选 Checkbox 时触发的事件selection
selection-change当选择项发生变化时会触发该事件selection
cell-mouse-enter当单元格 hover 进入时会触发该事件row, column, cell, event
cell-mouse-leave当单元格 hover 退出时会触发该事件row, column, cell, event
cell-click当某个单元格被点击时会触发该事件row, column, cell, event
row-click当某一行被点击时会触发该事件row, event
row-dblclick当某一行被双击时会触发该事件row, event
header-click当某一列的表头被点击时会触发该事件column, event
sort-change当表格的排序条件发生变化的时候会触发该事件{ column, prop, order }
current-change当表格的当前行发生变化的时候会触发该事件,如果要高亮当前行,请打开表格的 highlight-current-row 属性currentRow, oldCurrentRow

Table Methods

方法名说明参数
clearSelection清空用户的选择,当使用 reserve-selection 功能的时候,可能会需要使用此方法selection
toggleRowSelection切换某一行的选中状态,如果使用了第二个参数,则是设置这一行选中与否(selected 为 true 则选中)row, selected

Table-column Attributes

参数说明类型可选值默认值
type对应列的类型。如果设置了 selection 则显示多选框,如果设置了 index 则显示该行的索引(从 1 开始计算)stringselection/index
label显示的标题string
prop对应列内容的字段名,也可以使用 property 属性string
width对应列的宽度string
min-width对应列的最小宽度,与 width 的区别是 width 是固定的,min-width 会把剩余宽度按比例分配给设置了 min-width 的列string
fixed列是否固定在左侧或者右侧,true 表示固定在左侧string, booleantrue, left, right
render-header列标题 Label 区域渲染使用的 FunctionFunction(h, { column, $index })
sortable对应列是否可以排序,如果设置为 'custom',则代表用户希望远程排序,需要监听 Table 的 sort-change 事件boolean, stringtrue, false, 'custom'false
sort-method对数据进行排序的时候使用的方法,仅当 sortable 设置为 true 的时候有效Function(a, b)
sort-by对数据进行排序的时候按照 sort-by 排序,仅当 sortable 设置为 true 且没有设置 sort-method 的时候有效。如果 sort-by 为数组,则先按照第 0 个排序,如果第 0 个相等,再按照第 1 个排序,以此类推。Function(row, index)/String/Array
resizable对应列是否可以通过拖动改变宽度(需要在 el-table 上设置 border 属性为真)booleantrue
formatter用来格式化内容Function(row, column)
show-overflow-tooltip当内容过长被隐藏时显示 tooltipBooleanfalse
inline-template指定该属性后可以自定义 column 模板,参考多选的时间列,通过 row 获取行信息。总共可以获取到 { row(当前行), column(当前列), $index(行数), store(table store) } 以及 Table 所处的上下文环境。
align对齐方式Stringleft, center, rightleft
class-name列的 classNamestring
selectable仅对 type=selection 的列有效,类型为 Function,Function 的返回值用来决定这一行的 CheckBox 是否可以勾选Function(row, index)
reserve-selection仅对 type=selection 的列有效,类型为 Boolean,为 true 则代表会保留之前数据的选项,需要配合 Table 的 clearSelection 方法使用。Booleanfalse
filters数据过滤的选项,数组格式,数组中的元素需要有 text 和 value 属性。Array{ text, value }
filter-multiple数据过滤的选项是否多选Booleantrue
filter-method数据过滤使用的方法,如果是多选的筛选项,对每一条数据会执行多次,任意一次返回 true 就会显示。Function(value, row)
filtered-value选中的数据过滤项,如果需要自定义表头过滤的渲染方式,可能会需要此属性。Array

Development

make dev

## test
make test

## build
make build

License

MIT

2.2.2

6 years ago

2.0.0

6 years ago

1.0.0

7 years ago