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-default'
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
參數(shù) | 說(shuō)明 | 類型 | 可選值 | 默認(rèn)值 |
---|---|---|---|---|
data | 顯示的數(shù)據(jù) | array | — | — |
height | Table 的高度催什,默認(rèn)為自動(dòng)高度结执。如果 height 為 number 類型勉失,單位 px;如果 height 為 string 類型,則 Table 的高度受控于外部樣式。 | string/number | — | — |
stripe | 是否為斑馬紋 table | boolean | — | false |
border | 是否帶有縱向邊框 | boolean | — | false |
fit | 列的寬度是否自撐開 | boolean | — | true |
show-header | 是否顯示表頭 | boolean | - | true |
highlight-current-row | 是否要高亮當(dāng)前行 | boolean | — | false |
row-class-name | 行的 className 的回調(diào)方法,也可以使用字符串為所有行設(shè)置一個(gè)固定的 className纷铣。 | Function(row, index)/String | — | — |
row-style | 行的 style 的回調(diào)方法,也可以使用一個(gè)固定的 Object 為所有行設(shè)置一樣的 Style战转。 | Function(row, index)/Object | — | — |
row-key | 行數(shù)據(jù)的 Key搜立,用來(lái)優(yōu)化 Table 的渲染;在使用 reserve-selection 功能的情況下槐秧,該屬性是必填的 | Function(row)/String | — | — |
Table Events
事件名 | 說(shuō)明 | 參數(shù) |
---|---|---|
select | 當(dāng)用戶手動(dòng)勾選數(shù)據(jù)行的 Checkbox 時(shí)觸發(fā)的事件 | selection, row |
select-all | 當(dāng)用戶手動(dòng)勾選全選 Checkbox 時(shí)觸發(fā)的事件 | selection |
selection-change | 當(dāng)選擇項(xiàng)發(fā)生變化時(shí)會(huì)觸發(fā)該事件 | selection |
cell-mouse-enter | 當(dāng)單元格 hover 進(jìn)入時(shí)會(huì)觸發(fā)該事件 | row, column, cell, event |
cell-mouse-leave | 當(dāng)單元格 hover 退出時(shí)會(huì)觸發(fā)該事件 | row, column, cell, event |
cell-click | 當(dāng)某個(gè)單元格被點(diǎn)擊時(shí)會(huì)觸發(fā)該事件 | row, column, cell, event |
row-click | 當(dāng)某一行被點(diǎn)擊時(shí)會(huì)觸發(fā)該事件 | row, event |
row-dblclick | 當(dāng)某一行被雙擊時(shí)會(huì)觸發(fā)該事件 | row, event |
header-click | 當(dāng)某一列的表頭被點(diǎn)擊時(shí)會(huì)觸發(fā)該事件 | column, event |
sort-change | 當(dāng)表格的排序條件發(fā)生變化的時(shí)候會(huì)觸發(fā)該事件 | { column, prop, order } |
current-change | 當(dāng)表格的當(dāng)前行發(fā)生變化的時(shí)候會(huì)觸發(fā)該事件啄踊,如果要高亮當(dāng)前行,請(qǐng)打開表格的 highlight-current-row 屬性 | currentRow, oldCurrentRow |
Table Methods
方法名 | 說(shuō)明 | 參數(shù) |
---|---|---|
clearSelection | 清空用戶的選擇刁标,當(dāng)使用 reserve-selection 功能的時(shí)候颠通,可能會(huì)需要使用此方法 | selection |
toggleRowSelection | 切換某一行的選中狀態(tài),如果使用了第二個(gè)參數(shù)膀懈,則是設(shè)置這一行選中與否(selected 為 true 則選中) | row, selected |
Table-column Attributes
參數(shù) | 說(shuō)明 | 類型 | 可選值 | 默認(rèn)值 |
---|---|---|---|---|
type | 對(duì)應(yīng)列的類型顿锰。如果設(shè)置了 selection 則顯示多選框,如果設(shè)置了 index 則顯示該行的索引(從 1 開始計(jì)算) |
string | selection/index | — |
label | 顯示的標(biāo)題 | string | — | — |
prop | 對(duì)應(yīng)列內(nèi)容的字段名启搂,也可以使用 property 屬性 | string | — | — |
width | 對(duì)應(yīng)列的寬度 | string | — | — |
min-width | 對(duì)應(yīng)列的最小寬度硼控,與 width 的區(qū)別是 width 是固定的,min-width 會(huì)把剩余寬度按比例分配給設(shè)置了 min-width 的列 | string | — | — |
fixed | 列是否固定在左側(cè)或者右側(cè)狐血,true 表示固定在左側(cè) | string, boolean | true, left, right | — |
render-header | 列標(biāo)題 Label 區(qū)域渲染使用的 Function | Function(h, { column, $index }) | — | — |
sortable | 對(duì)應(yīng)列是否可以排序淀歇,如果設(shè)置為 'custom',則代表用戶希望遠(yuǎn)程排序匈织,需要監(jiān)聽 Table 的 sort-change 事件 | boolean, string | true, false, 'custom' | false |
sort-method | 對(duì)數(shù)據(jù)進(jìn)行排序的時(shí)候使用的方法,僅當(dāng) sortable 設(shè)置為 true 的時(shí)候有效 | Function(a, b) | — | — |
resizable | 對(duì)應(yīng)列是否可以通過拖動(dòng)改變寬度(需要在 el-table 上設(shè)置 border 屬性為真) | boolean | — | true |
formatter | 用來(lái)格式化內(nèi)容 | Function(row, column) | — | — |
show-overflow-tooltip | 當(dāng)內(nèi)容過長(zhǎng)被隱藏時(shí)顯示 tooltip | Boolean | — | false |
inline-template | 指定該屬性后可以自定義 column 模板牡直,參考多選的時(shí)間列缀匕,通過 row 獲取行信息∨鲆荩總共可以獲取到 { row(當(dāng)前行), column(當(dāng)前列), $index(行數(shù)), store(table store) } 以及 Table 所處的上下文環(huán)境乡小。 |
— | — | |
align | 對(duì)齊方式 | String | left, center, right | left |
class-name | 列的 className | string | — | — |
selectable | 僅對(duì) type=selection 的列有效,類型為 Function饵史,F(xiàn)unction 的返回值用來(lái)決定這一行的 CheckBox 是否可以勾選 | Function(row, index) | — | — |
reserve-selection | 僅對(duì) type=selection 的列有效满钟,類型為 Boolean胜榔,為 true 則代表會(huì)保留之前數(shù)據(jù)的選項(xiàng),需要配合 Table 的 clearSelection 方法使用湃番。 | Boolean | — | false |
filters | 數(shù)據(jù)過濾的選項(xiàng)夭织,數(shù)組格式,數(shù)組中的元素需要有 text 和 value 屬性吠撮。 | Array[{ text, value }] | — | — |
filter-multiple | 數(shù)據(jù)過濾的選項(xiàng)是否多選 | Boolean | — | true |
filter-method | 數(shù)據(jù)過濾使用的方法尊惰,如果是多選的篩選項(xiàng),對(duì)每一條數(shù)據(jù)會(huì)執(zhí)行多次深胳,任意一次返回 true 就會(huì)顯示庆聘。 | Function(value, row) | — | — |
filtered-value | 選中的數(shù)據(jù)過濾項(xiàng)好唯,如果需要自定義表頭過濾的渲染方式,可能會(huì)需要此屬性膀捷。 | Array | — | — |