0.1.0 • Published 6 years ago

custom-table v0.1.0

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

custom-table

A custom-table component for vue. --base element-ui 2.3.2

Installation

npm i custom-table -D

or
yarn add custom-table -D

# if you need
yarn add element-theme-chalk -D

Usage

import Vue from 'vue'
import CustomTable from 'custom-table'

Vue.use(CustomTable)

// or
// maybe you need to install element-theme-chalk as css style
import 'element-theme-chalk/lib/table.css'
import 'element-theme-chalk/lib/table-column.css'
import Vue from 'vue'
import {
    CustomTable,
    ExpendTable,
    CustomTableColumn,
    CustomTableWithSlot
} from 'custom-table'

Vue.component(CustomTable.name, CustomTable)
Vue.component(ExpendTable.name, ExpendTable)
Vue.component(CustomTableColumn.name, CustomTableColumn)
Vue.component(CustomTableWithSlot.name, CustomTableWithSlot)

Custom Table Attributes

参数说明类型可选值默认值
data表格数据any[][]
props表头数据any[]传送门[]
propsKey指定 data 数据的字段 keyObject传送门
其他el-table 指定可用 attributes传送门

propsKey

参数说明类型可选值默认值
label指定表格数据 label 字段为 data 的某个属性值string'label'
children指定表格数据 children 字段为 data 的某个属性值string'children'

Expand Table Attributes

参数说明类型可选值默认值
data表格数据any[][]
props表头数据any[]传送门[]
props-keydata 数据指定的字段 keyObject传送门
expand-keys默认展开行的键值string[][]
left折叠按钮位置,列number1
width表格默认最少宽度number80
*row-key行数据的 key,保证唯一性string默认以 props 的第一个值的 prop 作为 key
其他el-table 指定可用 attributes传送门

Custom Table With Slot Attributes

参数说明类型可选值默认值
data表格数据any[][]
props表头数据any[]传送门[]
propsKey指定 data 数据的字段 keyObject传送门
其他el-table 指定可用 attributes传送门
Custom Table With Slot 注:

props 中 children 字段无效,slot 需配合 showSlot 字段使用。

Table

Table Attributes

参数说明类型可选值默认值
data显示的数据array
heightTable 的高度,默认为自动高度。如果 height 为 number 类型,单位 px;如果 height 为 string 类型,则这个高度会设置为 Table 的 style.height 的值,Table 的高度会受控于外部样式。string/number
max-heightTable 的最大高度string/number
stripe是否为斑马纹 tablebooleanfalse
border是否带有纵向边框booleanfalse
sizeTable 的尺寸stringmedium / small / mini
fit列的宽度是否自撑开booleantrue
show-header是否显示表头booleantrue
highlight-current-row是否要高亮当前行booleanfalse
current-row-key当前行的 key,只写属性String,Number
row-class-name行的 className 的回调方法,也可以使用字符串为所有行设置一个固定的 className。Function({row, rowIndex})/String
row-style行的 style 的回调方法,也可以使用一个固定的 Object 为所有行设置一样的 Style。Function({row, rowIndex})/Object
cell-class-name单元格的 className 的回调方法,也可以使用字符串为所有单元格设置一个固定的 className。Function({row, column, rowIndex, columnIndex})/String
cell-style单元格的 style 的回调方法,也可以使用一个固定的 Object 为所有单元格设置一样的 Style。Function({row, column, rowIndex, columnIndex})/Object
header-row-class-name表头行的 className 的回调方法,也可以使用字符串为所有表头行设置一个固定的 className。Function({row, rowIndex})/String
header-row-style表头行的 style 的回调方法,也可以使用一个固定的 Object 为所有表头行设置一样的 Style。Function({row, rowIndex})/Object
header-cell-class-name表头单元格的 className 的回调方法,也可以使用字符串为所有表头单元格设置一个固定的 className。Function({row, column, rowIndex, columnIndex})/String
header-cell-style表头单元格的 style 的回调方法,也可以使用一个固定的 Object 为所有表头单元格设置一样的 Style。Function({row, rowIndex, rowIndex, columnIndex})/Object
row-key行数据的 Key,用来优化 Table 的渲染;在使用 reserve-selection 功能的情况下,该属性是必填的。类型为 String 时,支持多层访问:user.info.id,但不支持 user.info[0].id,此种情况请使用 FunctionFunction(row)/String
empty-text空数据时显示的文本内容,也可以通过 slot="empty" 设置String暂无数据
default-expand-all是否默认展开所有行,当 Table 中存在 type="expand" 的 Column 的时候有效Booleanfalse
expand-row-keys可以通过该属性设置 Table 目前的展开行,需要设置 row-key 属性才能使用,该属性为展开行的 keys 数组。Array
default-sort默认的排序列的prop和顺序。它的prop属性指定默认的排序的列,order指定默认排序的顺序Objectorder: ascending, descending如果只指定了prop, 没有指定order, 则默认顺序是ascending
tooltip-effecttooltip effect 属性Stringdark/lightdark
show-summary是否在表尾显示合计行Booleanfalse
sum-text合计行第一列的文本String合计
summary-method自定义的合计计算方法Function({ columns, data })
span-method合并行或列的计算方法Function({ row, column, rowIndex, columnIndex })
select-on-indeterminate在多选表格中,当仅有部分行被选中时,点击表头的多选框时的行为。若为 true,则选中所有行;若为 false,则取消选择所有行Booleantrue

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
cell-dblclick当某个单元格被双击击时会触发该事件row, column, cell, event
row-click当某一行被点击时会触发该事件row, event, column
row-contextmenu当某一行被鼠标右键点击时会触发该事件row, event
row-dblclick当某一行被双击时会触发该事件row, event
header-click当某一列的表头被点击时会触发该事件column, event
header-contextmenu当某一列的表头被鼠标右键点击时触发该事件column, event
sort-change当表格的排序条件发生变化的时候会触发该事件{ column, prop, order }
filter-change当表格的筛选条件发生变化的时候会触发该事件,参数的值是一个对象,对象的 key 是 column 的 columnKey,对应的 value 为用户选择的筛选条件的数组。filters
current-change当表格的当前行发生变化的时候会触发该事件,如果要高亮当前行,请打开表格的 highlight-current-row 属性currentRow, oldCurrentRow
header-dragend当拖动表头改变了列的宽度的时候会触发该事件newWidth, oldWidth, column, event
expand-change当用户对某一行展开或者关闭的时候会触发该事件row, expandedRows

Table Methods

方法名说明参数
clearSelection用于多选表格,清空用户的选择
toggleRowSelection用于多选表格,切换某一行的选中状态,如果使用了第二个参数,则是设置这一行选中与否(selected 为 true 则选中)row, selected
toggleRowExpansion用于可展开表格,切换某一行的展开状态,如果使用了第二个参数,则是设置这一行展开与否(expanded 为 true 则展开)row, expanded
setCurrentRow用于单选表格,设定某一行为选中行,如果调用时不加参数,则会取消目前高亮行的选中状态。row
clearSort用于清空排序条件,数据会恢复成未排序的状态
clearFilter用于清空过滤条件,数据会恢复成未过滤的状态
doLayout对 Table 进行重新布局。当 Table 或其祖先元素由隐藏切换为显示时,可能需要调用此方法

License

MIT