2016-07-27 14:15:02 +08:00
|
|
|
|
<script>
|
|
|
|
|
import Vue from 'vue';
|
|
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
tableData: [{
|
2016-09-19 17:55:44 +08:00
|
|
|
|
date: '2016-05-03',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
2016-10-27 21:45:21 +08:00
|
|
|
|
zip: 200333,
|
|
|
|
|
tag: '家'
|
2016-09-19 17:55:44 +08:00
|
|
|
|
}, {
|
2016-07-27 14:15:02 +08:00
|
|
|
|
date: '2016-05-02',
|
|
|
|
|
name: '王小虎',
|
2016-09-19 17:55:44 +08:00
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
2016-10-27 21:45:21 +08:00
|
|
|
|
zip: 200333,
|
|
|
|
|
tag: '公司'
|
2016-07-27 14:15:02 +08:00
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-04',
|
|
|
|
|
name: '王小虎',
|
2016-09-19 17:55:44 +08:00
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
2016-10-27 21:45:21 +08:00
|
|
|
|
zip: 200333,
|
|
|
|
|
tag: '家'
|
2016-07-27 14:15:02 +08:00
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-01',
|
|
|
|
|
name: '王小虎',
|
2016-09-19 17:55:44 +08:00
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
2016-10-27 21:45:21 +08:00
|
|
|
|
zip: 200333,
|
|
|
|
|
tag: '公司'
|
2016-07-27 14:15:02 +08:00
|
|
|
|
}],
|
|
|
|
|
tableData2: [{
|
|
|
|
|
date: '2016-05-02',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-04',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
$info: true
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-01',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-03',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
$positive: true
|
|
|
|
|
}],
|
|
|
|
|
tableData3: [{
|
|
|
|
|
date: '2016-05-03',
|
|
|
|
|
name: '王小虎',
|
2016-09-19 17:55:44 +08:00
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
zip: 200333
|
2016-07-27 14:15:02 +08:00
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-02',
|
|
|
|
|
name: '王小虎',
|
2016-09-19 17:55:44 +08:00
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
zip: 200333
|
2016-07-27 14:15:02 +08:00
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-04',
|
|
|
|
|
name: '王小虎',
|
2016-09-19 17:55:44 +08:00
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
zip: 200333
|
2016-07-27 14:15:02 +08:00
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-01',
|
|
|
|
|
name: '王小虎',
|
2016-09-19 17:55:44 +08:00
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
zip: 200333
|
2016-07-27 14:15:02 +08:00
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-08',
|
|
|
|
|
name: '王小虎',
|
2016-09-19 17:55:44 +08:00
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
zip: 200333
|
2016-07-27 14:15:02 +08:00
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-06',
|
|
|
|
|
name: '王小虎',
|
2016-09-19 17:55:44 +08:00
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
zip: 200333
|
2016-07-27 14:15:02 +08:00
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-07',
|
|
|
|
|
name: '王小虎',
|
2016-09-19 17:55:44 +08:00
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
zip: 200333
|
2016-07-27 14:15:02 +08:00
|
|
|
|
}],
|
|
|
|
|
singleSelection: {},
|
|
|
|
|
multipleSelection: []
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
|
2016-08-16 16:07:18 +08:00
|
|
|
|
methods: {
|
|
|
|
|
handleSelectionChange(val) {
|
2016-08-16 16:52:43 +08:00
|
|
|
|
this.multipleSelection = val;
|
2016-08-23 15:24:26 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
formatter(row, column) {
|
|
|
|
|
return row.address;
|
2016-10-12 19:18:34 +08:00
|
|
|
|
},
|
|
|
|
|
|
2016-10-27 21:45:21 +08:00
|
|
|
|
filterTag(value, row) {
|
|
|
|
|
return row.tag === value;
|
|
|
|
|
},
|
|
|
|
|
|
2016-10-12 19:18:34 +08:00
|
|
|
|
tableRowClassName(row, index) {
|
|
|
|
|
if (index === 1) {
|
|
|
|
|
return 'info-row';
|
|
|
|
|
} else if (index === 3) {
|
|
|
|
|
return 'positive-row';
|
|
|
|
|
}
|
|
|
|
|
return '';
|
2016-08-16 16:52:43 +08:00
|
|
|
|
}
|
2016-08-16 16:07:18 +08:00
|
|
|
|
},
|
|
|
|
|
|
2016-07-27 14:15:02 +08:00
|
|
|
|
watch: {
|
2016-08-16 16:52:43 +08:00
|
|
|
|
multipleSelection(val) {
|
|
|
|
|
console.log('selection: ', val);
|
|
|
|
|
}
|
2016-07-27 14:15:02 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
2016-10-12 19:18:34 +08:00
|
|
|
|
<style>
|
|
|
|
|
.el-table .info-row {
|
|
|
|
|
background: #c9e5f5;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.el-table .positive-row {
|
|
|
|
|
background: #e2f0e4;
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
|
2016-08-26 19:46:45 +08:00
|
|
|
|
## Table 表格
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-08-26 19:46:45 +08:00
|
|
|
|
用于展示多条结构类似的数据,可对数据进行排序、筛选、对比或其他自定义操作。
|
2016-08-23 15:24:26 +08:00
|
|
|
|
|
2016-08-26 19:46:45 +08:00
|
|
|
|
### 基础表格
|
2016-08-23 15:24:26 +08:00
|
|
|
|
|
2016-09-08 09:15:35 +08:00
|
|
|
|
基础的表格展示用法。
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-10-12 19:18:34 +08:00
|
|
|
|
:::demo 当`el-table`元素中注入`data`对象数组后,在`el-table-column`中用`prop`属性来对应对象中的键名即可填入数据,用`label`属性来定义表格的列名。可以使用`width`属性来定义列宽。
|
2016-07-27 14:15:02 +08:00
|
|
|
|
```html
|
2016-08-26 19:46:45 +08:00
|
|
|
|
<template>
|
|
|
|
|
<el-table
|
|
|
|
|
:data="tableData"
|
2016-09-19 17:55:44 +08:00
|
|
|
|
style="width: 100%">
|
2016-08-26 19:46:45 +08:00
|
|
|
|
<el-table-column
|
2016-10-12 19:18:34 +08:00
|
|
|
|
prop="date"
|
2016-08-26 19:46:45 +08:00
|
|
|
|
label="日期"
|
2016-09-19 17:55:44 +08:00
|
|
|
|
width="180">
|
2016-08-26 19:46:45 +08:00
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
2016-10-12 19:18:34 +08:00
|
|
|
|
prop="name"
|
2016-08-26 19:46:45 +08:00
|
|
|
|
label="姓名"
|
2016-09-19 17:55:44 +08:00
|
|
|
|
width="180">
|
2016-08-26 19:46:45 +08:00
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
2016-10-12 19:18:34 +08:00
|
|
|
|
prop="address"
|
2016-08-26 19:46:45 +08:00
|
|
|
|
label="地址">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
</el-table>
|
|
|
|
|
</template>
|
2016-08-26 18:34:54 +08:00
|
|
|
|
|
2016-08-26 19:46:45 +08:00
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
tableData: [{
|
|
|
|
|
date: '2016-05-02',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄'
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-04',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1517 弄'
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-01',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1519 弄'
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-03',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1516 弄'
|
|
|
|
|
}]
|
|
|
|
|
}
|
2016-07-27 14:15:02 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-08-26 19:46:45 +08:00
|
|
|
|
</script>
|
2016-07-27 14:15:02 +08:00
|
|
|
|
```
|
2016-08-26 19:46:45 +08:00
|
|
|
|
:::
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-08-26 19:46:45 +08:00
|
|
|
|
### 带斑马纹表格
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-09-08 09:15:35 +08:00
|
|
|
|
使用带斑马纹的表格,可以更容易区分出不同行的数据。
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-08-26 19:46:45 +08:00
|
|
|
|
:::demo `stripe`属性可以创建带斑马纹的表格。它接受一个`Boolean`,默认为`false`,设置为`true`即为启用。
|
2016-07-27 14:15:02 +08:00
|
|
|
|
```html
|
|
|
|
|
<template>
|
2016-08-26 19:46:45 +08:00
|
|
|
|
<el-table
|
|
|
|
|
:data="tableData"
|
|
|
|
|
stripe
|
2016-09-19 17:55:44 +08:00
|
|
|
|
style="width: 100%">
|
2016-08-26 19:46:45 +08:00
|
|
|
|
<el-table-column
|
2016-10-12 19:18:34 +08:00
|
|
|
|
prop="date"
|
2016-08-26 19:46:45 +08:00
|
|
|
|
label="日期"
|
2016-09-19 17:55:44 +08:00
|
|
|
|
width="180">
|
2016-08-26 19:46:45 +08:00
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
2016-10-12 19:18:34 +08:00
|
|
|
|
prop="name"
|
2016-08-26 19:46:45 +08:00
|
|
|
|
label="姓名"
|
2016-09-19 17:55:44 +08:00
|
|
|
|
width="180">
|
2016-08-26 19:46:45 +08:00
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
2016-10-12 19:18:34 +08:00
|
|
|
|
prop="address"
|
2016-08-26 19:46:45 +08:00
|
|
|
|
label="地址">
|
|
|
|
|
</el-table-column>
|
2016-07-27 14:15:02 +08:00
|
|
|
|
</el-table>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
tableData: [{
|
|
|
|
|
date: '2016-05-02',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄'
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-04',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1517 弄'
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-01',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1519 弄'
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-03',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1516 弄'
|
|
|
|
|
}]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
```
|
2016-08-26 19:46:45 +08:00
|
|
|
|
:::
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-08-26 19:46:45 +08:00
|
|
|
|
### 带边框表格
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-08-26 19:46:45 +08:00
|
|
|
|
:::demo 默认情况下,Table 组件是不具有竖直方向的边框的,如果需要,可以使用`border`属性,它接受一个`Boolean`,设置为`true`即可启用。
|
2016-07-27 14:15:02 +08:00
|
|
|
|
```html
|
|
|
|
|
<template>
|
2016-08-26 19:46:45 +08:00
|
|
|
|
<el-table
|
|
|
|
|
:data="tableData"
|
|
|
|
|
border
|
2016-09-19 17:55:44 +08:00
|
|
|
|
style="width: 100%">
|
2016-08-26 19:46:45 +08:00
|
|
|
|
<el-table-column
|
2016-10-12 19:18:34 +08:00
|
|
|
|
prop="date"
|
2016-08-26 19:46:45 +08:00
|
|
|
|
label="日期"
|
2016-09-19 17:55:44 +08:00
|
|
|
|
width="180">
|
2016-08-26 19:46:45 +08:00
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
2016-10-12 19:18:34 +08:00
|
|
|
|
prop="name"
|
2016-08-26 19:46:45 +08:00
|
|
|
|
label="姓名"
|
2016-09-19 17:55:44 +08:00
|
|
|
|
width="180">
|
2016-08-26 19:46:45 +08:00
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
2016-10-12 19:18:34 +08:00
|
|
|
|
prop="address"
|
2016-08-26 19:46:45 +08:00
|
|
|
|
label="地址">
|
|
|
|
|
</el-table-column>
|
2016-07-27 14:15:02 +08:00
|
|
|
|
</el-table>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
tableData: [{
|
|
|
|
|
date: '2016-05-02',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄'
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-04',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1517 弄'
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-01',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1519 弄'
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-03',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1516 弄'
|
|
|
|
|
}]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
```
|
2016-08-26 19:46:45 +08:00
|
|
|
|
:::
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-08-26 19:46:45 +08:00
|
|
|
|
### 带状态表格
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-09-08 09:15:35 +08:00
|
|
|
|
可将表格内容 highlight 显示,方便区分「成功、信息、警告、危险」等内容。
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-10-12 19:18:34 +08:00
|
|
|
|
:::demo 可以通过指定 Table 组件的 rowClassName 属性来为 Table 中的某一行添加 class,表明该行处于某种状态。
|
2016-07-27 14:15:02 +08:00
|
|
|
|
```html
|
|
|
|
|
<template>
|
2016-08-26 19:46:45 +08:00
|
|
|
|
<el-table
|
|
|
|
|
:data="tableData2"
|
2016-09-19 17:55:44 +08:00
|
|
|
|
style="width: 100%"
|
2016-10-12 19:18:34 +08:00
|
|
|
|
:row-class-name="tableRowClassName">
|
2016-08-26 19:46:45 +08:00
|
|
|
|
<el-table-column
|
2016-10-12 19:18:34 +08:00
|
|
|
|
prop="date"
|
2016-08-26 19:46:45 +08:00
|
|
|
|
label="日期"
|
2016-09-19 17:55:44 +08:00
|
|
|
|
width="180">
|
2016-08-26 19:46:45 +08:00
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
2016-10-12 19:18:34 +08:00
|
|
|
|
prop="name"
|
2016-08-26 19:46:45 +08:00
|
|
|
|
label="姓名"
|
2016-09-19 17:55:44 +08:00
|
|
|
|
width="180">
|
2016-08-26 19:46:45 +08:00
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
2016-10-12 19:18:34 +08:00
|
|
|
|
prop="address"
|
2016-08-26 19:46:45 +08:00
|
|
|
|
label="地址">
|
|
|
|
|
</el-table-column>
|
2016-07-27 14:15:02 +08:00
|
|
|
|
</el-table>
|
|
|
|
|
</template>
|
|
|
|
|
|
2016-10-12 19:18:34 +08:00
|
|
|
|
<style>
|
|
|
|
|
.el-table .info-row {
|
|
|
|
|
background: #c9e5f5;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.el-table .positive-row {
|
|
|
|
|
background: #e2f0e4;
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
|
2016-07-27 14:15:02 +08:00
|
|
|
|
<script>
|
|
|
|
|
export default {
|
2016-10-12 19:18:34 +08:00
|
|
|
|
methods: {
|
|
|
|
|
tableRowClassName(row, index) {
|
|
|
|
|
if (index === 1) {
|
|
|
|
|
return 'info-row';
|
|
|
|
|
} else if (index === 3) {
|
|
|
|
|
return 'positive-row';
|
|
|
|
|
}
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
},
|
2016-07-27 14:15:02 +08:00
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
tableData2: [{
|
|
|
|
|
date: '2016-05-02',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-04',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
$info: true
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-01',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-03',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
$positive: true
|
|
|
|
|
}]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
```
|
2016-08-26 19:46:45 +08:00
|
|
|
|
:::
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-08-26 19:46:45 +08:00
|
|
|
|
### 固定表头
|
2016-08-23 15:24:26 +08:00
|
|
|
|
|
2016-09-08 09:15:35 +08:00
|
|
|
|
纵向内容过多时,可选择固定表头。
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-08-26 19:46:45 +08:00
|
|
|
|
:::demo 只要在`el-table`元素中定义了`height`属性,即可实现固定表头的表格,而不需要额外的代码。
|
2016-07-27 14:15:02 +08:00
|
|
|
|
```html
|
|
|
|
|
<template>
|
2016-08-26 18:34:54 +08:00
|
|
|
|
<el-table
|
2016-08-26 19:46:45 +08:00
|
|
|
|
:data="tableData3"
|
|
|
|
|
height="250"
|
|
|
|
|
border
|
2016-09-19 17:55:44 +08:00
|
|
|
|
style="width: 100%">
|
2016-08-26 19:46:45 +08:00
|
|
|
|
<el-table-column
|
2016-10-12 19:18:34 +08:00
|
|
|
|
prop="date"
|
2016-08-26 19:46:45 +08:00
|
|
|
|
label="日期"
|
2016-09-19 17:55:44 +08:00
|
|
|
|
width="180">
|
2016-08-26 19:46:45 +08:00
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
2016-10-12 19:18:34 +08:00
|
|
|
|
prop="name"
|
2016-08-26 19:46:45 +08:00
|
|
|
|
label="姓名"
|
2016-09-19 17:55:44 +08:00
|
|
|
|
width="180">
|
2016-08-26 19:46:45 +08:00
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
2016-10-12 19:18:34 +08:00
|
|
|
|
prop="address"
|
2016-08-26 19:46:45 +08:00
|
|
|
|
label="地址">
|
|
|
|
|
</el-table-column>
|
2016-07-27 14:15:02 +08:00
|
|
|
|
</el-table>
|
|
|
|
|
</template>
|
2016-08-16 16:07:18 +08:00
|
|
|
|
|
2016-07-27 14:15:02 +08:00
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
tableData3: [{
|
|
|
|
|
date: '2016-05-03',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄'
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-02',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄'
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-04',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄'
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-01',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄'
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-08',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄'
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-06',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄'
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-07',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄'
|
|
|
|
|
}]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
```
|
2016-08-26 19:46:45 +08:00
|
|
|
|
:::
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-08-26 19:46:45 +08:00
|
|
|
|
### 固定列
|
2016-08-23 15:24:26 +08:00
|
|
|
|
|
2016-10-19 21:57:12 +08:00
|
|
|
|
横向内容过多时,可选择固定列。
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-10-12 19:18:34 +08:00
|
|
|
|
:::demo 固定列需要使用`fixed`属性,它接受 Boolean 值或者`left` `right`,表示左边固定还是右边固定。
|
2016-07-27 14:15:02 +08:00
|
|
|
|
```html
|
|
|
|
|
<template>
|
2016-08-26 19:46:45 +08:00
|
|
|
|
<el-table
|
|
|
|
|
:data="tableData"
|
|
|
|
|
border
|
2016-09-19 17:55:44 +08:00
|
|
|
|
style="width: 100%">
|
2016-08-26 19:46:45 +08:00
|
|
|
|
<el-table-column
|
2016-10-12 19:18:34 +08:00
|
|
|
|
fixed
|
|
|
|
|
prop="date"
|
2016-08-26 19:46:45 +08:00
|
|
|
|
label="日期"
|
|
|
|
|
width="150">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
2016-10-12 19:18:34 +08:00
|
|
|
|
prop="name"
|
2016-08-26 19:46:45 +08:00
|
|
|
|
label="姓名"
|
2016-09-19 17:55:44 +08:00
|
|
|
|
width="120">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
2016-10-12 19:18:34 +08:00
|
|
|
|
prop="province"
|
2016-09-19 17:55:44 +08:00
|
|
|
|
label="省份"
|
|
|
|
|
width="120">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
2016-10-12 19:18:34 +08:00
|
|
|
|
prop="city"
|
2016-09-19 17:55:44 +08:00
|
|
|
|
label="市区"
|
|
|
|
|
width="120">
|
2016-08-26 19:46:45 +08:00
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
2016-10-12 19:18:34 +08:00
|
|
|
|
prop="address"
|
2016-08-26 19:46:45 +08:00
|
|
|
|
label="地址"
|
|
|
|
|
width="300">
|
|
|
|
|
</el-table-column>
|
2016-09-19 17:55:44 +08:00
|
|
|
|
<el-table-column
|
2016-10-12 19:18:34 +08:00
|
|
|
|
prop="zip"
|
2016-09-19 17:55:44 +08:00
|
|
|
|
label="邮编"
|
|
|
|
|
width="120">
|
|
|
|
|
</el-table-column>
|
2016-10-19 21:57:12 +08:00
|
|
|
|
<el-table-column
|
|
|
|
|
inline-template
|
|
|
|
|
fixed="right"
|
|
|
|
|
label="操作"
|
|
|
|
|
width="80">
|
2016-10-28 17:51:57 +08:00
|
|
|
|
<el-button type="text" size="small">编辑</el-button>
|
2016-10-19 21:57:12 +08:00
|
|
|
|
</el-table-column>
|
2016-07-27 14:15:02 +08:00
|
|
|
|
</el-table>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
tableData: [{
|
2016-09-19 17:55:44 +08:00
|
|
|
|
date: '2016-05-03',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
zip: 200333
|
|
|
|
|
}, {
|
2016-07-27 14:15:02 +08:00
|
|
|
|
date: '2016-05-02',
|
|
|
|
|
name: '王小虎',
|
2016-09-19 17:55:44 +08:00
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
zip: 200333
|
2016-07-27 14:15:02 +08:00
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-04',
|
|
|
|
|
name: '王小虎',
|
2016-09-19 17:55:44 +08:00
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
zip: 200333
|
2016-07-27 14:15:02 +08:00
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-01',
|
|
|
|
|
name: '王小虎',
|
2016-09-19 17:55:44 +08:00
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
zip: 200333
|
2016-07-27 14:15:02 +08:00
|
|
|
|
}]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
```
|
2016-08-26 19:46:45 +08:00
|
|
|
|
:::
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-08-26 19:46:45 +08:00
|
|
|
|
### 固定列和表头
|
2016-08-23 15:24:26 +08:00
|
|
|
|
|
2016-09-08 09:15:35 +08:00
|
|
|
|
横纵内容过多时,可选择固定列和表头。
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-08-26 19:46:45 +08:00
|
|
|
|
:::demo 固定列和表头可以同时使用,只需要将上述两个属性分别设置好即可。
|
2016-07-27 14:15:02 +08:00
|
|
|
|
```html
|
|
|
|
|
<template>
|
2016-08-26 19:46:45 +08:00
|
|
|
|
<el-table
|
|
|
|
|
:data="tableData3"
|
|
|
|
|
border
|
2016-09-19 17:55:44 +08:00
|
|
|
|
style="width: 100%"
|
2016-08-26 19:46:45 +08:00
|
|
|
|
height="250">
|
|
|
|
|
<el-table-column
|
2016-10-12 19:18:34 +08:00
|
|
|
|
fixed
|
|
|
|
|
prop="date"
|
2016-08-26 19:46:45 +08:00
|
|
|
|
label="日期"
|
|
|
|
|
width="150">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
2016-10-12 19:18:34 +08:00
|
|
|
|
prop="name"
|
2016-08-26 19:46:45 +08:00
|
|
|
|
label="姓名"
|
2016-09-19 17:55:44 +08:00
|
|
|
|
width="120">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
2016-10-12 19:18:34 +08:00
|
|
|
|
prop="province"
|
2016-09-19 17:55:44 +08:00
|
|
|
|
label="省份"
|
|
|
|
|
width="120">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
2016-10-12 19:18:34 +08:00
|
|
|
|
prop="city"
|
2016-09-19 17:55:44 +08:00
|
|
|
|
label="市区"
|
|
|
|
|
width="120">
|
2016-08-26 19:46:45 +08:00
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
2016-10-12 19:18:34 +08:00
|
|
|
|
prop="address"
|
2016-08-26 19:46:45 +08:00
|
|
|
|
label="地址"
|
|
|
|
|
width="300">
|
|
|
|
|
</el-table-column>
|
2016-09-19 17:55:44 +08:00
|
|
|
|
<el-table-column
|
2016-10-12 19:18:34 +08:00
|
|
|
|
prop="zip"
|
2016-09-19 17:55:44 +08:00
|
|
|
|
label="邮编"
|
|
|
|
|
width="120">
|
|
|
|
|
</el-table-column>
|
2016-07-27 14:15:02 +08:00
|
|
|
|
</el-table>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
tableData3: [{
|
|
|
|
|
date: '2016-05-03',
|
|
|
|
|
name: '王小虎',
|
2016-09-19 17:55:44 +08:00
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
zip: 200333
|
2016-07-27 14:15:02 +08:00
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-02',
|
|
|
|
|
name: '王小虎',
|
2016-09-19 17:55:44 +08:00
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
zip: 200333
|
2016-07-27 14:15:02 +08:00
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-04',
|
|
|
|
|
name: '王小虎',
|
2016-09-19 17:55:44 +08:00
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
zip: 200333
|
2016-07-27 14:15:02 +08:00
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-01',
|
|
|
|
|
name: '王小虎',
|
2016-09-19 17:55:44 +08:00
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
zip: 200333
|
2016-07-27 14:15:02 +08:00
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-08',
|
|
|
|
|
name: '王小虎',
|
2016-09-19 17:55:44 +08:00
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
zip: 200333
|
2016-07-27 14:15:02 +08:00
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-06',
|
|
|
|
|
name: '王小虎',
|
2016-09-19 17:55:44 +08:00
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
zip: 200333
|
2016-07-27 14:15:02 +08:00
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-07',
|
|
|
|
|
name: '王小虎',
|
2016-09-19 17:55:44 +08:00
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
zip: 200333
|
2016-07-27 14:15:02 +08:00
|
|
|
|
}]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
```
|
2016-08-26 19:46:45 +08:00
|
|
|
|
:::
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-08-26 19:46:45 +08:00
|
|
|
|
### 多选
|
2016-08-23 15:24:26 +08:00
|
|
|
|
|
2016-09-08 09:15:35 +08:00
|
|
|
|
选择多行数据时使用 Checkbox。
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-10-21 16:35:28 +08:00
|
|
|
|
:::demo 实现多选非常简单: 手动添加一个`el-table-column`,设`type`属性为`selection`即可。在本例中,为了方便说明其他属性,我们还使用了`inline-template`和`show-tooltip-when-overflow`:设置了`inline-template`属性后,可以通过调用`row`对象中的值取代`prop`属性的设置;默认情况下若内容过多会折行显示,若需要单行显示可以使用`show-tooltip-when-overflow`属性,它接受一个`Boolean`,为`true`时多余的内容会在 hover 时以 tooltip 的形式显示出来。
|
2016-07-27 14:15:02 +08:00
|
|
|
|
```html
|
|
|
|
|
<template>
|
2016-08-26 19:46:45 +08:00
|
|
|
|
<el-table
|
|
|
|
|
:data="tableData3"
|
2016-10-30 11:32:06 +08:00
|
|
|
|
border
|
2016-09-19 17:55:44 +08:00
|
|
|
|
style="width: 100%"
|
2016-10-30 11:31:43 +08:00
|
|
|
|
@selection-change="handleSelectionChange">
|
2016-08-26 19:46:45 +08:00
|
|
|
|
<el-table-column
|
|
|
|
|
type="selection"
|
|
|
|
|
width="50">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
|
|
|
|
inline-template
|
|
|
|
|
label="日期"
|
|
|
|
|
width="120">
|
2016-08-16 16:07:18 +08:00
|
|
|
|
<div>{{ row.date }}</div>
|
|
|
|
|
</el-table-column>
|
2016-08-26 19:46:45 +08:00
|
|
|
|
<el-table-column
|
2016-10-12 19:18:34 +08:00
|
|
|
|
prop="name"
|
2016-08-26 19:46:45 +08:00
|
|
|
|
label="姓名"
|
|
|
|
|
width="120">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
2016-10-12 19:18:34 +08:00
|
|
|
|
prop="address"
|
2016-08-26 19:46:45 +08:00
|
|
|
|
label="地址"
|
|
|
|
|
show-tooltip-when-overflow>
|
|
|
|
|
</el-table-column>
|
2016-07-27 14:15:02 +08:00
|
|
|
|
</el-table>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
tableData3: [{
|
|
|
|
|
date: '2016-05-03',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄'
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-02',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄'
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-04',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄'
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-01',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄'
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-08',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄'
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-06',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄'
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-07',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄'
|
|
|
|
|
}],
|
|
|
|
|
multipleSelection: []
|
|
|
|
|
}
|
2016-08-16 16:07:18 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
|
handleSelectionChange(val) {
|
|
|
|
|
this.multipleSelection = val;
|
|
|
|
|
}
|
2016-07-27 14:15:02 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
```
|
2016-08-26 19:46:45 +08:00
|
|
|
|
:::
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-08-26 19:46:45 +08:00
|
|
|
|
### 排序
|
2016-08-23 15:24:26 +08:00
|
|
|
|
|
2016-09-08 09:15:35 +08:00
|
|
|
|
对表格进行排序,可快速查找或对比数据。
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-08-26 19:46:45 +08:00
|
|
|
|
:::demo 在列中设置`sortable`属性即可实现以该列为基准的排序,接受一个`Boolean`,默认为`false`。在本例中,我们还使用了`formatter`属性,它用于格式化指定列的值,接受一个`Function`,会传入两个参数:`row`和`column`,可以根据自己的需求进行处理。
|
2016-07-27 14:15:02 +08:00
|
|
|
|
```html
|
|
|
|
|
<template>
|
2016-08-26 19:46:45 +08:00
|
|
|
|
<el-table
|
|
|
|
|
:data="tableData"
|
|
|
|
|
border
|
2016-09-19 17:55:44 +08:00
|
|
|
|
style="width: 100%">
|
2016-08-26 19:46:45 +08:00
|
|
|
|
<el-table-column
|
2016-10-12 19:18:34 +08:00
|
|
|
|
prop="date"
|
2016-08-26 19:46:45 +08:00
|
|
|
|
label="日期"
|
|
|
|
|
sortable
|
2016-09-19 17:55:44 +08:00
|
|
|
|
width="180">
|
2016-08-26 19:46:45 +08:00
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
2016-10-12 19:18:34 +08:00
|
|
|
|
prop="name"
|
2016-08-26 19:46:45 +08:00
|
|
|
|
label="姓名"
|
2016-09-19 17:55:44 +08:00
|
|
|
|
width="180">
|
2016-08-26 19:46:45 +08:00
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
2016-10-12 19:18:34 +08:00
|
|
|
|
prop="address"
|
2016-08-26 19:46:45 +08:00
|
|
|
|
label="地址"
|
|
|
|
|
:formatter="formatter">
|
|
|
|
|
</el-table-column>
|
2016-07-27 14:15:02 +08:00
|
|
|
|
</el-table>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
tableData: [{
|
|
|
|
|
date: '2016-05-02',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄'
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-04',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1517 弄'
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-01',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1519 弄'
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-03',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1516 弄'
|
|
|
|
|
}]
|
|
|
|
|
}
|
2016-08-23 15:24:26 +08:00
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
formatter(row, column) {
|
|
|
|
|
return row.address;
|
|
|
|
|
}
|
2016-07-27 14:15:02 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
```
|
2016-08-26 19:46:45 +08:00
|
|
|
|
:::
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-10-27 21:45:21 +08:00
|
|
|
|
### 筛选
|
|
|
|
|
|
|
|
|
|
对表格进行筛选,可快速查找到自己想看的数据。
|
|
|
|
|
|
2016-10-27 23:25:03 +08:00
|
|
|
|
:::demo 在列中设置`filters` `filter-method`属性即可开启该列的筛选,filters 是一个数组,`filter-method`是一个方法,它用于决定某些数据是否显示,会传入两个参数:`value`和`row`。
|
2016-10-27 21:45:21 +08:00
|
|
|
|
```html
|
|
|
|
|
<template>
|
|
|
|
|
<el-table
|
|
|
|
|
:data="tableData"
|
|
|
|
|
border
|
|
|
|
|
style="width: 100%">
|
|
|
|
|
<el-table-column
|
|
|
|
|
prop="date"
|
|
|
|
|
label="日期"
|
|
|
|
|
sortable
|
|
|
|
|
width="180">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
|
|
|
|
prop="name"
|
|
|
|
|
label="姓名"
|
|
|
|
|
width="180">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
|
|
|
|
prop="address"
|
|
|
|
|
label="地址"
|
|
|
|
|
:formatter="formatter">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
|
|
|
|
prop="tag"
|
|
|
|
|
label="标签"
|
|
|
|
|
width="100"
|
|
|
|
|
:filters="[{ text: '家', value: '家' }, { text: '公司', value: '公司' }]"
|
|
|
|
|
:filter-method="filterTag"
|
|
|
|
|
inline-template>
|
|
|
|
|
<el-tag :type="row.tag === '家' ? 'primary' : 'success'" close-transition>{{row.tag}}</el-tag>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
</el-table>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
tableData: [{
|
|
|
|
|
date: '2016-05-02',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
tag: '家'
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-04',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1517 弄',
|
|
|
|
|
tag: '公司'
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-01',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1519 弄',
|
|
|
|
|
tag: '家'
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-03',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1516 弄',
|
|
|
|
|
tag: '公司'
|
|
|
|
|
}]
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
formatter(row, column) {
|
|
|
|
|
return row.address;
|
|
|
|
|
},
|
|
|
|
|
filterTag(value, row) {
|
|
|
|
|
return row.tag === value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
```
|
|
|
|
|
:::
|
|
|
|
|
|
2016-08-26 19:46:45 +08:00
|
|
|
|
### Table Attributes
|
2016-07-27 14:15:02 +08:00
|
|
|
|
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|
|
|
|
|
|---------- |-------------- |---------- |-------------------------------- |-------- |
|
2016-09-02 13:56:47 +08:00
|
|
|
|
| data | 显示的数据 | array | — | — |
|
2016-10-24 19:01:55 +08:00
|
|
|
|
| height | table 的高度,默认高度为空,即自动高度,单位 px | string, number | — | — |
|
2016-09-02 13:56:47 +08:00
|
|
|
|
| stripe | 是否为斑马纹 table | boolean | — | false |
|
|
|
|
|
| border | 是否带有纵向边框 | boolean | — | false |
|
2016-09-29 16:39:53 +08:00
|
|
|
|
| fit | 列的宽度是否自撑开 | boolean | — | true |
|
2016-11-04 16:15:33 +08:00
|
|
|
|
| highlight-current-row | 是否要高亮当前行 | boolean | - | false |
|
2016-10-24 19:01:55 +08:00
|
|
|
|
| row-class-name | 行的 className 的回调。 | Function(row, index) | - | - |
|
|
|
|
|
| row-key | 行数据的 Key,用来优化 Table 的渲染;在使用 reserve-selection 功能的情况下,该属性是必填的 | Function(row), String | - | - |
|
2016-08-26 19:46:45 +08:00
|
|
|
|
|
|
|
|
|
### Table Events
|
2016-07-27 14:15:02 +08:00
|
|
|
|
| 事件名 | 说明 | 参数 |
|
|
|
|
|
| ---- | ---- | ---- |
|
2016-10-24 19:01:55 +08:00
|
|
|
|
| select | 当用户手动勾选数据行的 Checkbox 时触发的事件 | selection, row |
|
2016-10-19 18:53:31 +08:00
|
|
|
|
| select-all | 当用户手动勾选全选 Checkbox 时触发的事件 | selection |
|
|
|
|
|
| selection-change | 当选择项发生变化时会触发该事件 | selection |
|
2016-10-21 17:53:49 +08:00
|
|
|
|
| cell-mouse-enter | 当单元格 hover 进入时会触发该事件 | row, column, cell, event |
|
|
|
|
|
| cell-mouse-leave | 当单元格 hover 退出时会触发该事件 | row, column, cell, event |
|
2016-10-19 18:53:31 +08:00
|
|
|
|
| cell-click | 当某个单元格被点击时会触发该事件 | row, column, cell, event |
|
|
|
|
|
| row-click | 当某一行被点击时会触发该事件 | row, event |
|
2016-10-28 01:24:13 +08:00
|
|
|
|
| sort-change | 当表格的排序条件发生变化的时候会触发该事件 | { column, prop, order } |
|
2016-11-04 16:15:33 +08:00
|
|
|
|
| current-change | 当表格的当前行发生变化的时候会触发该事件,如果要高亮当前行,请打开表格的 highlight-current-row 属性 | { column, prop, order } |
|
2016-10-19 18:53:31 +08:00
|
|
|
|
|
|
|
|
|
### Table Methods
|
|
|
|
|
| 方法名 | 说明 | 参数 |
|
|
|
|
|
| ---- | ---- | ---- |
|
|
|
|
|
| clearSelection | 清空用户的选择,当使用 reserve-selection 功能的时候,可能会需要使用此方法 | selection |
|
2016-11-03 14:42:18 +08:00
|
|
|
|
| toggleRowSelection | 切换某一行的选中状态,如果使用了第二个参数,则是设置这一行选中与否(selected 为 true 则选中) | row, selected |
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-08-26 19:46:45 +08:00
|
|
|
|
### Table-column Attributes
|
2016-07-27 14:15:02 +08:00
|
|
|
|
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|
|
|
|
|
|---------- |-------------- |---------- |-------------------------------- |-------- |
|
2016-09-02 13:56:47 +08:00
|
|
|
|
| label | 显示的标题 | string | — | — |
|
2016-10-12 19:18:34 +08:00
|
|
|
|
| prop | 对应列内容的字段名,也可以使用 property 属性 | string | — | — |
|
2016-09-02 13:56:47 +08:00
|
|
|
|
| width | 对应列的宽度 | string | — | — |
|
2016-10-31 15:49:41 +08:00
|
|
|
|
| min-width | 对应列的最小宽度,与 width 的区别是 width 是固定的,min-width 会把剩余宽度按比例分配给设置了 min-width 的列 | string | — | — |
|
2016-10-24 19:01:55 +08:00
|
|
|
|
| fixed | 列是否固定在左侧或者右侧,true 表示固定在左侧 | string, boolean | true, left, right | - |
|
2016-10-28 01:24:13 +08:00
|
|
|
|
| sortable | 对应列是否可以排序,如果设置为 'custom',则代表用户希望远程排序,需要监听 Table 的 sort-change 事件 | boolean, string | true, false, 'custom' | false |
|
|
|
|
|
| sort-method | 对数据进行排序的时候使用的方法,仅当 sortable 设置为 true 的时候有效 | Function(a, b) | - | - |
|
2016-10-24 19:01:55 +08:00
|
|
|
|
| resizable | 对应列是否可以通过拖动改变宽度(如果需要在 el-table 上设置 border 属性为真) | boolean | — | true |
|
2016-09-02 13:56:47 +08:00
|
|
|
|
| type | 对应列的类型。如果设置了 `selection` 则显示多选框,如果设置了 `index` 则显示该行的索引(从 1 开始计算) | string | selection/index | — |
|
2016-10-24 19:01:55 +08:00
|
|
|
|
| formatter | 用来格式化内容 | Function(row, column) | — | — |
|
2016-09-02 13:56:47 +08:00
|
|
|
|
| show-tooltip-when-overflow | 当过长被隐藏时显示 tooltip | Boolean | — | false |
|
2016-10-30 15:31:35 +08:00
|
|
|
|
| inline-template | 指定该属性后可以自定义 column 模板,参考多选的时间列,通过 row 获取行信息,JSX 里通过 _self 获取当前上下文。此时不需要配置 prop 属性。总共可以获取到 `{ row(当前行), column(当前列), $index(行数), _self(当前上下文), store(table store) }` 的信息。 | — | — |
|
2016-09-21 06:20:36 +08:00
|
|
|
|
| align | 对齐方式 | String | left, center, right | left |
|
2016-10-24 19:01:55 +08:00
|
|
|
|
| selectable | 仅对 type=selection 的列有效,类型为 Function,Function 的返回值用来决定这一行的 CheckBox 是否可以勾选 | Function(row, index) | - | - |
|
2016-10-27 21:45:21 +08:00
|
|
|
|
| reserve-selection | 仅对 type=selection 的列有效,类型为 Boolean,为 true 则代表会保留之前数据的选项,需要配合 Table 的 clearSelection 方法使用。 | Boolean | - | false |
|
|
|
|
|
| filters | 数据过滤的选项,数组格式,数组中的元素需要有 text 和 value 属性。 | Array[{ text, value }] | — | — |
|
|
|
|
|
| filter-multiple | 数据过滤的选项是否多选 | Boolean | — | true |
|
|
|
|
|
| filter-method | 数据过滤使用的方法,如果是多选的筛选项,对每一条数据会执行多次,任意一次返回 true 就会显示。 | Function(value, row) | — | — |
|
2016-10-28 09:47:10 +08:00
|
|
|
|
| filtered-value | 选中的数据过滤项,如果需要自定义表头过滤的渲染方式,可能会需要此属性。 | Array | — | — |
|