2016-07-27 14:15:02 +08:00
|
|
|
|
<script>
|
|
|
|
|
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 弄',
|
2016-11-12 23:08:17 +08:00
|
|
|
|
detailAddress: '金沙江路 1518 弄',
|
2016-09-19 17:55:44 +08:00
|
|
|
|
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 弄',
|
2016-11-12 23:08:17 +08:00
|
|
|
|
detailAddress: '金沙江路 1518 弄',
|
2016-09-19 17:55:44 +08:00
|
|
|
|
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 弄',
|
2016-12-29 17:20:59 +08:00
|
|
|
|
detailAddress: '金沙江路 1518 弄',
|
2016-09-19 17:55:44 +08:00
|
|
|
|
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 弄',
|
2016-11-12 23:08:17 +08:00
|
|
|
|
detailAddress: '金沙江路 1518 弄',
|
2016-09-19 17:55:44 +08:00
|
|
|
|
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 弄',
|
2016-11-12 23:08:17 +08:00
|
|
|
|
detailAddress: '金沙江路 1518 弄',
|
2016-09-19 17:55:44 +08:00
|
|
|
|
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 弄',
|
2016-11-12 23:08:17 +08:00
|
|
|
|
detailAddress: '金沙江路 1518 弄',
|
2016-09-19 17:55:44 +08:00
|
|
|
|
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 弄',
|
2016-11-12 23:08:17 +08:00
|
|
|
|
detailAddress: '金沙江路 1518 弄',
|
2016-09-19 17:55:44 +08:00
|
|
|
|
zip: 200333
|
2016-07-27 14:15:02 +08:00
|
|
|
|
}],
|
2016-12-14 13:42:56 +08:00
|
|
|
|
tableData4: [{
|
|
|
|
|
date: '2016-05-03',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
zip: 200333
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-02',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
zip: 200333
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-04',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
zip: 200333
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-01',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
zip: 200333
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-08',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
zip: 200333
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-06',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
zip: 200333
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-07',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
zip: 200333
|
|
|
|
|
}],
|
2017-02-22 15:02:34 +08:00
|
|
|
|
tableData5: [{
|
|
|
|
|
id: '12987122',
|
|
|
|
|
name: '好滋好味鸡蛋仔',
|
|
|
|
|
category: '江浙小吃、小吃零食',
|
|
|
|
|
desc: '荷兰优质淡奶,奶香浓而不腻',
|
|
|
|
|
address: '上海市普陀区真北路',
|
|
|
|
|
shop: '王小虎夫妻店',
|
|
|
|
|
shopId: '10333'
|
|
|
|
|
}, {
|
|
|
|
|
id: '12987123',
|
|
|
|
|
name: '好滋好味鸡蛋仔',
|
|
|
|
|
category: '江浙小吃、小吃零食',
|
|
|
|
|
desc: '荷兰优质淡奶,奶香浓而不腻',
|
|
|
|
|
address: '上海市普陀区真北路',
|
|
|
|
|
shop: '王小虎夫妻店',
|
|
|
|
|
shopId: '10333'
|
|
|
|
|
}, {
|
|
|
|
|
id: '12987125',
|
|
|
|
|
name: '好滋好味鸡蛋仔',
|
|
|
|
|
category: '江浙小吃、小吃零食',
|
|
|
|
|
desc: '荷兰优质淡奶,奶香浓而不腻',
|
|
|
|
|
address: '上海市普陀区真北路',
|
|
|
|
|
shop: '王小虎夫妻店',
|
|
|
|
|
shopId: '10333'
|
|
|
|
|
}, {
|
|
|
|
|
id: '12987126',
|
|
|
|
|
name: '好滋好味鸡蛋仔',
|
|
|
|
|
category: '江浙小吃、小吃零食',
|
|
|
|
|
desc: '荷兰优质淡奶,奶香浓而不腻',
|
|
|
|
|
address: '上海市普陀区真北路',
|
|
|
|
|
shop: '王小虎夫妻店',
|
|
|
|
|
shopId: '10333'
|
|
|
|
|
}],
|
2017-04-28 15:53:39 +08:00
|
|
|
|
tableData6: [{
|
|
|
|
|
id: '12987122',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
amount1: '234',
|
|
|
|
|
amount2: '3.2',
|
|
|
|
|
amount3: 10
|
|
|
|
|
}, {
|
|
|
|
|
id: '12987123',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
amount1: '165',
|
|
|
|
|
amount2: '4.43',
|
|
|
|
|
amount3: 12
|
|
|
|
|
}, {
|
|
|
|
|
id: '12987124',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
amount1: '324',
|
|
|
|
|
amount2: '1.9',
|
|
|
|
|
amount3: 9
|
|
|
|
|
}, {
|
|
|
|
|
id: '12987125',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
amount1: '621',
|
|
|
|
|
amount2: '2.2',
|
|
|
|
|
amount3: 17
|
|
|
|
|
}, {
|
|
|
|
|
id: '12987126',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
amount1: '539',
|
|
|
|
|
amount2: '4.1',
|
|
|
|
|
amount3: 15
|
|
|
|
|
}],
|
2016-11-08 15:59:14 +08:00
|
|
|
|
currentRow: null,
|
2016-07-27 14:15:02 +08:00
|
|
|
|
multipleSelection: []
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
|
2016-08-16 16:07:18 +08:00
|
|
|
|
methods: {
|
2017-04-28 15:53:39 +08:00
|
|
|
|
getSummaries(param) {
|
|
|
|
|
const { columns, data } = param;
|
|
|
|
|
const sums = [];
|
|
|
|
|
columns.forEach((column, index) => {
|
|
|
|
|
if (index === 0) {
|
|
|
|
|
sums[index] = '总价';
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const values = data.map(item => Number(item[column.property]));
|
|
|
|
|
if (!values.every(value => isNaN(value))) {
|
|
|
|
|
sums[index] = values.reduce((prev, curr) => {
|
|
|
|
|
const value = Number(curr);
|
|
|
|
|
if (!isNaN(value)) {
|
|
|
|
|
return prev + curr;
|
|
|
|
|
} else {
|
|
|
|
|
return prev;
|
|
|
|
|
}
|
|
|
|
|
}, 0);
|
|
|
|
|
sums[index] += ' 元';
|
|
|
|
|
} else {
|
|
|
|
|
sums[index] = 'N/A';
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return sums;
|
|
|
|
|
},
|
2017-04-22 01:11:32 +08:00
|
|
|
|
setCurrent(row) {
|
|
|
|
|
this.$refs.singleTable.setCurrentRow(row);
|
|
|
|
|
},
|
|
|
|
|
toggleSelection(rows) {
|
|
|
|
|
if (rows) {
|
|
|
|
|
rows.forEach(row => {
|
|
|
|
|
this.$refs.multipleTable.toggleRowSelection(row);
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
this.$refs.multipleTable.clearSelection();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2017-09-25 15:13:06 +08:00
|
|
|
|
handleClick(row) {
|
|
|
|
|
console.log(row);
|
2016-11-18 15:00:22 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
handleEdit(index, row) {
|
|
|
|
|
console.log(index, row);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
handleDelete(index, row) {
|
|
|
|
|
console.log(index, row);
|
|
|
|
|
},
|
|
|
|
|
|
2016-08-16 16:07:18 +08:00
|
|
|
|
handleSelectionChange(val) {
|
2016-08-16 16:52:43 +08:00
|
|
|
|
this.multipleSelection = val;
|
2016-08-23 15:24:26 +08:00
|
|
|
|
},
|
|
|
|
|
|
2016-11-08 15:59:14 +08:00
|
|
|
|
handleCurrentChange(val) {
|
|
|
|
|
this.currentRow = 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;
|
|
|
|
|
},
|
|
|
|
|
|
2018-01-15 12:25:53 +08:00
|
|
|
|
filterHandler(value, row, column) {
|
|
|
|
|
const property = column['property'];
|
|
|
|
|
return row[property] === value;
|
|
|
|
|
},
|
|
|
|
|
|
2017-10-28 15:54:12 +08:00
|
|
|
|
tableRowClassName({row, rowIndex}) {
|
|
|
|
|
if (rowIndex === 1) {
|
2017-10-25 11:58:58 +08:00
|
|
|
|
return 'warning-row';
|
2017-10-28 15:54:12 +08:00
|
|
|
|
} else if (rowIndex === 3) {
|
2017-10-25 11:58:58 +08:00
|
|
|
|
return 'success-row';
|
2016-10-12 19:18:34 +08:00
|
|
|
|
}
|
|
|
|
|
return '';
|
2016-12-14 13:42:56 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
deleteRow(index, rows) {
|
|
|
|
|
rows.splice(index, 1);
|
2017-10-20 11:00:29 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
arraySpanMethod({ row, column, rowIndex, columnIndex }) {
|
|
|
|
|
if (rowIndex % 2 === 0) {
|
|
|
|
|
if (columnIndex === 0) {
|
|
|
|
|
return [1, 2];
|
|
|
|
|
} else if (columnIndex === 1) {
|
|
|
|
|
return [0, 0];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
objectSpanMethod({ row, column, rowIndex, columnIndex }) {
|
|
|
|
|
if (columnIndex === 0) {
|
|
|
|
|
if (rowIndex % 2 === 0) {
|
|
|
|
|
return {
|
|
|
|
|
rowspan: 2,
|
|
|
|
|
colspan: 1
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
return {
|
|
|
|
|
rowspan: 0,
|
|
|
|
|
colspan: 0
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-10-25 15:35:12 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
indexMethod(index) {
|
|
|
|
|
return index * 2;
|
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>
|
2017-10-25 11:58:58 +08:00
|
|
|
|
.el-table .warning-row {
|
|
|
|
|
background: oldlace;
|
2016-10-12 19:18:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-25 11:58:58 +08:00
|
|
|
|
.el-table .success-row {
|
|
|
|
|
background: #f0f9eb;
|
2016-10-12 19:18:34 +08:00
|
|
|
|
}
|
2016-12-14 11:57:25 +08:00
|
|
|
|
|
2016-11-28 18:25:55 +08:00
|
|
|
|
.demo-table .name-wrapper {
|
|
|
|
|
display: inline-block;
|
|
|
|
|
}
|
2017-02-28 17:12:11 +08:00
|
|
|
|
|
2017-02-22 15:02:34 +08:00
|
|
|
|
.demo-table .demo-table-expand {
|
|
|
|
|
label {
|
|
|
|
|
width: 90px;
|
|
|
|
|
color: #99a9bf;
|
|
|
|
|
}
|
|
|
|
|
.el-form-item {
|
|
|
|
|
margin-right: 0;
|
|
|
|
|
margin-bottom: 0;
|
|
|
|
|
width: 50%;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-12 19:18:34 +08:00
|
|
|
|
</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-11-13 11:58:45 +08:00
|
|
|
|
:::demo 可以通过指定 Table 组件的 `row-class-name` 属性来为 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>
|
2017-10-25 11:58:58 +08:00
|
|
|
|
.el-table .warning-row {
|
|
|
|
|
background: oldlace;
|
2016-10-12 19:18:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-25 11:58:58 +08:00
|
|
|
|
.el-table .success-row {
|
|
|
|
|
background: #f0f9eb;
|
2016-10-12 19:18:34 +08:00
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
|
2016-07-27 14:15:02 +08:00
|
|
|
|
<script>
|
|
|
|
|
export default {
|
2016-10-12 19:18:34 +08:00
|
|
|
|
methods: {
|
2017-10-25 15:35:12 +08:00
|
|
|
|
tableRowClassName({row, rowIndex}) {
|
|
|
|
|
if (rowIndex === 1) {
|
2017-10-25 11:58:58 +08:00
|
|
|
|
return 'warning-row';
|
2017-10-25 15:35:12 +08:00
|
|
|
|
} else if (rowIndex === 3) {
|
2017-10-25 11:58:58 +08:00
|
|
|
|
return 'success-row';
|
2016-10-12 19:18:34 +08:00
|
|
|
|
}
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
},
|
2016-07-27 14:15:02 +08:00
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
tableData2: [{
|
|
|
|
|
date: '2016-05-02',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-04',
|
|
|
|
|
name: '王小虎',
|
2016-11-13 11:58:45 +08:00
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄'
|
2016-07-27 14:15:02 +08:00
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-01',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-03',
|
|
|
|
|
name: '王小虎',
|
2016-11-13 11:58:45 +08:00
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄'
|
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 只要在`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
|
|
|
|
|
fixed="right"
|
|
|
|
|
label="操作"
|
2016-11-07 10:47:51 +08:00
|
|
|
|
width="100">
|
2017-10-16 14:07:24 +08:00
|
|
|
|
<template slot-scope="scope">
|
2017-09-25 15:13:06 +08:00
|
|
|
|
<el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>
|
2016-11-07 10:47:51 +08:00
|
|
|
|
<el-button type="text" size="small">编辑</el-button>
|
2016-12-20 10:47:16 +08:00
|
|
|
|
</template>
|
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 {
|
2016-11-18 15:00:22 +08:00
|
|
|
|
methods: {
|
2017-09-25 15:13:06 +08:00
|
|
|
|
handleClick(row) {
|
|
|
|
|
console.log(row);
|
2016-11-18 15:00:22 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2016-07-27 14:15:02 +08:00
|
|
|
|
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"
|
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>
|
|
|
|
|
|
2016-11-23 20:32:23 +08:00
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
tableData3: [{
|
|
|
|
|
date: '2016-05-03',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
zip: 200333
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-02',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
zip: 200333
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-04',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
zip: 200333
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-01',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
zip: 200333
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-08',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
zip: 200333
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-06',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
zip: 200333
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-07',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
zip: 200333
|
|
|
|
|
}]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
```
|
|
|
|
|
:::
|
|
|
|
|
|
2016-12-14 13:42:56 +08:00
|
|
|
|
### 流体高度
|
|
|
|
|
|
|
|
|
|
当数据量动态变化时,可以为 Table 设置一个最大高度。
|
|
|
|
|
|
|
|
|
|
:::demo 通过设置`max-height`属性为 Table 指定最大高度。此时若表格所需的高度大于最大高度,则会显示一个滚动条。
|
|
|
|
|
```html
|
|
|
|
|
<template>
|
|
|
|
|
<el-table
|
|
|
|
|
:data="tableData4"
|
|
|
|
|
style="width: 100%"
|
|
|
|
|
max-height="250">
|
|
|
|
|
<el-table-column
|
|
|
|
|
fixed
|
|
|
|
|
prop="date"
|
|
|
|
|
label="日期"
|
|
|
|
|
width="150">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
|
|
|
|
prop="name"
|
|
|
|
|
label="姓名"
|
|
|
|
|
width="120">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
|
|
|
|
prop="province"
|
|
|
|
|
label="省份"
|
|
|
|
|
width="120">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
|
|
|
|
prop="city"
|
|
|
|
|
label="市区"
|
|
|
|
|
width="120">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
|
|
|
|
prop="address"
|
|
|
|
|
label="地址"
|
|
|
|
|
width="300">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
|
|
|
|
prop="zip"
|
|
|
|
|
label="邮编"
|
|
|
|
|
width="120">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
|
|
|
|
fixed="right"
|
|
|
|
|
label="操作"
|
|
|
|
|
width="120">
|
2017-10-16 14:07:24 +08:00
|
|
|
|
<template slot-scope="scope">
|
2016-12-14 13:42:56 +08:00
|
|
|
|
<el-button
|
2016-12-20 10:47:16 +08:00
|
|
|
|
@click.native.prevent="deleteRow(scope.$index, tableData4)"
|
2016-12-14 13:42:56 +08:00
|
|
|
|
type="text"
|
|
|
|
|
size="small">
|
|
|
|
|
移除
|
|
|
|
|
</el-button>
|
2016-12-20 10:47:16 +08:00
|
|
|
|
</template>
|
2016-12-14 13:42:56 +08:00
|
|
|
|
</el-table-column>
|
|
|
|
|
</el-table>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
methods: {
|
|
|
|
|
deleteRow(index, rows) {
|
|
|
|
|
rows.splice(index, 1);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
tableData4: [{
|
|
|
|
|
date: '2016-05-03',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
zip: 200333
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-02',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
zip: 200333
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-04',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
zip: 200333
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-01',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
zip: 200333
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-08',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
zip: 200333
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-06',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
zip: 200333
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-07',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
zip: 200333
|
|
|
|
|
}]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
```
|
|
|
|
|
:::
|
|
|
|
|
|
2016-11-23 20:32:23 +08:00
|
|
|
|
### 多级表头
|
|
|
|
|
|
|
|
|
|
数据结构比较复杂的时候,可使用多级表头来展现数据的层次关系。
|
|
|
|
|
|
|
|
|
|
:::demo 只需要在 el-table-column 里面嵌套 el-table-column,就可以实现多级表头。
|
|
|
|
|
```html
|
|
|
|
|
<template>
|
|
|
|
|
<el-table
|
|
|
|
|
:data="tableData3"
|
|
|
|
|
style="width: 100%">
|
|
|
|
|
<el-table-column
|
|
|
|
|
prop="date"
|
|
|
|
|
label="日期"
|
|
|
|
|
width="150">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column label="配送信息">
|
|
|
|
|
<el-table-column
|
|
|
|
|
prop="name"
|
|
|
|
|
label="姓名"
|
|
|
|
|
width="120">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column label="地址">
|
|
|
|
|
<el-table-column
|
|
|
|
|
prop="province"
|
|
|
|
|
label="省份"
|
|
|
|
|
width="120">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
|
|
|
|
prop="city"
|
|
|
|
|
label="市区"
|
|
|
|
|
width="120">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
|
|
|
|
prop="address"
|
|
|
|
|
label="地址"
|
|
|
|
|
width="300">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
|
|
|
|
prop="zip"
|
|
|
|
|
label="邮编"
|
|
|
|
|
width="120">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
</el-table>
|
|
|
|
|
</template>
|
|
|
|
|
|
2016-07-27 14:15:02 +08:00
|
|
|
|
<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-11-08 15:59:14 +08:00
|
|
|
|
### 单选
|
|
|
|
|
|
|
|
|
|
选择单行数据时使用色块表示。
|
|
|
|
|
|
|
|
|
|
:::demo Table 组件提供了单选的支持,只需要配置`highlight-current-row`属性即可实现单选。之后由`current-change`事件来管理选中时触发的事件,它会传入`currentRow`,`oldCurrentRow`。如果需要显示索引,可以增加一列`el-table-column`,设置`type`属性为`index`即可显示从 1 开始的索引号。
|
|
|
|
|
```html
|
|
|
|
|
<template>
|
|
|
|
|
<el-table
|
2017-04-22 01:11:32 +08:00
|
|
|
|
ref="singleTable"
|
2016-11-08 15:59:14 +08:00
|
|
|
|
:data="tableData"
|
|
|
|
|
highlight-current-row
|
|
|
|
|
@current-change="handleCurrentChange"
|
|
|
|
|
style="width: 100%">
|
|
|
|
|
<el-table-column
|
|
|
|
|
type="index"
|
|
|
|
|
width="50">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
|
|
|
|
property="date"
|
|
|
|
|
label="日期"
|
|
|
|
|
width="120">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
|
|
|
|
property="name"
|
|
|
|
|
label="姓名"
|
|
|
|
|
width="120">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
|
|
|
|
property="address"
|
|
|
|
|
label="地址">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
</el-table>
|
2017-04-22 01:11:32 +08:00
|
|
|
|
<div style="margin-top: 20px">
|
|
|
|
|
<el-button @click="setCurrent(tableData[1])">选中第二行</el-button>
|
|
|
|
|
<el-button @click="setCurrent()">取消选择</el-button>
|
|
|
|
|
</div>
|
2016-11-08 15:59:14 +08:00
|
|
|
|
</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 弄'
|
|
|
|
|
}],
|
|
|
|
|
currentRow: null
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
methods: {
|
2017-04-22 01:11:32 +08:00
|
|
|
|
setCurrent(row) {
|
|
|
|
|
this.$refs.singleTable.setCurrentRow(row);
|
|
|
|
|
},
|
2016-11-08 15:59:14 +08:00
|
|
|
|
handleCurrentChange(val) {
|
|
|
|
|
this.currentRow = val;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
```
|
|
|
|
|
:::
|
|
|
|
|
|
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-12-20 10:47:16 +08:00
|
|
|
|
:::demo 实现多选非常简单: 手动添加一个`el-table-column`,设`type`属性为`selection`即可;默认情况下若内容过多会折行显示,若需要单行显示可以使用`show-overflow-tooltip`属性,它接受一个`Boolean`,为`true`时多余的内容会在 hover 时以 tooltip 的形式显示出来。
|
2016-07-27 14:15:02 +08:00
|
|
|
|
```html
|
|
|
|
|
<template>
|
2016-08-26 19:46:45 +08:00
|
|
|
|
<el-table
|
2017-04-22 01:11:32 +08:00
|
|
|
|
ref="multipleTable"
|
2016-08-26 19:46:45 +08:00
|
|
|
|
:data="tableData3"
|
2017-03-29 11:59:12 +08:00
|
|
|
|
tooltip-effect="dark"
|
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"
|
2016-12-08 14:11:19 +08:00
|
|
|
|
width="55">
|
2016-08-26 19:46:45 +08:00
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
|
|
|
|
label="日期"
|
|
|
|
|
width="120">
|
2017-10-16 14:07:24 +08:00
|
|
|
|
<template slot-scope="scope">{{ scope.row.date }}</template>
|
2016-08-16 16:07:18 +08:00
|
|
|
|
</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="地址"
|
2016-11-04 16:27:51 +08:00
|
|
|
|
show-overflow-tooltip>
|
2016-08-26 19:46:45 +08:00
|
|
|
|
</el-table-column>
|
2016-07-27 14:15:02 +08:00
|
|
|
|
</el-table>
|
2017-04-22 01:11:32 +08:00
|
|
|
|
<div style="margin-top: 20px">
|
|
|
|
|
<el-button @click="toggleSelection([tableData3[1], tableData3[2]])">切换第二、第三行的选中状态</el-button>
|
|
|
|
|
<el-button @click="toggleSelection()">取消选择</el-button>
|
|
|
|
|
</div>
|
2016-07-27 14:15:02 +08:00
|
|
|
|
</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: {
|
2017-04-22 01:11:32 +08:00
|
|
|
|
toggleSelection(rows) {
|
|
|
|
|
if (rows) {
|
|
|
|
|
rows.forEach(row => {
|
|
|
|
|
this.$refs.multipleTable.toggleRowSelection(row);
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
this.$refs.multipleTable.clearSelection();
|
|
|
|
|
}
|
|
|
|
|
},
|
2016-08-16 16:07:18 +08:00
|
|
|
|
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
|
|
|
|
|
2017-10-30 10:26:25 +08:00
|
|
|
|
:::demo 在列中设置`sortable`属性即可实现以该列为基准的排序,接受一个`Boolean`,默认为`false`。可以通过 Table 的`default-sort`属性设置默认的排序列和排序顺序。可以使用`sort-method`或者`sort-by`使用自定义的排序规则。如果需要后端排序,需将`sortable`设置为`custom`,同时在 Table 上监听`sort-change`事件,在事件回调中可以获取当前排序的字段名和排序顺序,从而向接口请求排序后的表格数据。在本例中,我们还使用了`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"
|
2017-01-05 12:38:39 +08:00
|
|
|
|
style="width: 100%"
|
2017-01-14 14:51:44 +08:00
|
|
|
|
:default-sort = "{prop: 'date', order: 'descending'}"
|
2017-01-05 12:38:39 +08:00
|
|
|
|
>
|
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="姓名"
|
2017-01-14 14:51:44 +08:00
|
|
|
|
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="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
|
|
|
|
### 筛选
|
|
|
|
|
|
|
|
|
|
对表格进行筛选,可快速查找到自己想看的数据。
|
|
|
|
|
|
2018-01-15 12:25:53 +08:00
|
|
|
|
:::demo 在列中设置`filters` `filter-method`属性即可开启该列的筛选,filters 是一个数组,`filter-method`是一个方法,它用于决定某些数据是否显示,会传入三个参数:`value`, `row` 和 `column`。
|
2016-10-27 21:45:21 +08:00
|
|
|
|
```html
|
|
|
|
|
<template>
|
|
|
|
|
<el-table
|
|
|
|
|
:data="tableData"
|
|
|
|
|
style="width: 100%">
|
|
|
|
|
<el-table-column
|
|
|
|
|
prop="date"
|
|
|
|
|
label="日期"
|
|
|
|
|
sortable
|
2018-01-15 12:25:53 +08:00
|
|
|
|
width="180"
|
|
|
|
|
:filters="[{text: '2016-05-01', value: '2016-05-01'}, {text: '2016-05-02', value: '2016-05-02'}, {text: '2016-05-03', value: '2016-05-03'}, {text: '2016-05-04', value: '2016-05-04'}]"
|
|
|
|
|
:filter-method="filterHandler"
|
|
|
|
|
>
|
2016-10-27 21:45:21 +08:00
|
|
|
|
</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: '公司' }]"
|
2017-04-27 14:08:59 +08:00
|
|
|
|
:filter-method="filterTag"
|
2017-05-03 15:23:38 +08:00
|
|
|
|
filter-placement="bottom-end">
|
2017-10-16 14:07:24 +08:00
|
|
|
|
<template slot-scope="scope">
|
2016-12-20 10:47:16 +08:00
|
|
|
|
<el-tag
|
|
|
|
|
:type="scope.row.tag === '家' ? 'primary' : 'success'"
|
|
|
|
|
close-transition>{{scope.row.tag}}</el-tag>
|
|
|
|
|
</template>
|
2016-10-27 21:45:21 +08:00
|
|
|
|
</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;
|
2018-01-15 12:25:53 +08:00
|
|
|
|
},
|
|
|
|
|
filterHandler(value, row, column) {
|
|
|
|
|
const property = column['property'];
|
|
|
|
|
return row[property] === value;
|
2016-10-27 21:45:21 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
```
|
|
|
|
|
:::
|
|
|
|
|
|
2016-11-18 15:00:22 +08:00
|
|
|
|
### 自定义列模板
|
|
|
|
|
|
|
|
|
|
自定义列的显示内容,可组合其他组件使用。
|
2017-12-18 17:38:51 +08:00
|
|
|
|
:::demo 通过 `Scoped slot` 可以获取到 row, column, $index 和 store(table 内部的状态管理)的数据,用法参考 demo。
|
2016-11-18 15:00:22 +08:00
|
|
|
|
```html
|
|
|
|
|
<template>
|
|
|
|
|
<el-table
|
|
|
|
|
:data="tableData"
|
|
|
|
|
style="width: 100%">
|
|
|
|
|
<el-table-column
|
|
|
|
|
label="日期"
|
|
|
|
|
width="180">
|
2017-10-16 14:07:24 +08:00
|
|
|
|
<template slot-scope="scope">
|
2017-10-18 18:31:03 +08:00
|
|
|
|
<i class="el-icon-time"></i>
|
2016-12-20 10:47:16 +08:00
|
|
|
|
<span style="margin-left: 10px">{{ scope.row.date }}</span>
|
|
|
|
|
</template>
|
2016-11-18 15:00:22 +08:00
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
|
|
|
|
label="姓名"
|
|
|
|
|
width="180">
|
2017-10-16 14:07:24 +08:00
|
|
|
|
<template slot-scope="scope">
|
2016-12-20 10:47:16 +08:00
|
|
|
|
<el-popover trigger="hover" placement="top">
|
|
|
|
|
<p>姓名: {{ scope.row.name }}</p>
|
|
|
|
|
<p>住址: {{ scope.row.address }}</p>
|
|
|
|
|
<div slot="reference" class="name-wrapper">
|
2017-10-18 18:31:03 +08:00
|
|
|
|
<el-tag size="medium">{{ scope.row.name }}</el-tag>
|
2016-12-20 10:47:16 +08:00
|
|
|
|
</div>
|
|
|
|
|
</el-popover>
|
|
|
|
|
</template>
|
2016-11-18 15:00:22 +08:00
|
|
|
|
</el-table-column>
|
2016-12-20 10:47:16 +08:00
|
|
|
|
<el-table-column label="操作">
|
2017-10-16 14:07:24 +08:00
|
|
|
|
<template slot-scope="scope">
|
2016-11-18 15:00:22 +08:00
|
|
|
|
<el-button
|
2017-10-18 18:31:03 +08:00
|
|
|
|
size="mini"
|
2016-12-20 10:47:16 +08:00
|
|
|
|
@click="handleEdit(scope.$index, scope.row)">编辑</el-button>
|
2016-11-18 15:00:22 +08:00
|
|
|
|
<el-button
|
2017-10-18 18:31:03 +08:00
|
|
|
|
size="mini"
|
2016-11-18 15:00:22 +08:00
|
|
|
|
type="danger"
|
2016-12-20 10:47:16 +08:00
|
|
|
|
@click="handleDelete(scope.$index, scope.row)">删除</el-button>
|
|
|
|
|
</template>
|
2016-11-18 15:00:22 +08:00
|
|
|
|
</el-table-column>
|
|
|
|
|
</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 弄'
|
|
|
|
|
}]
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
handleEdit(index, row) {
|
|
|
|
|
console.log(index, row);
|
|
|
|
|
},
|
|
|
|
|
handleDelete(index, row) {
|
|
|
|
|
console.log(index, row);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
```
|
|
|
|
|
:::
|
|
|
|
|
|
2016-11-12 23:08:17 +08:00
|
|
|
|
### 展开行
|
|
|
|
|
|
|
|
|
|
当行内容过多并且不想显示横向滚动条时,可以使用 Table 展开行功能。
|
2016-12-28 18:33:26 +08:00
|
|
|
|
:::demo 通过设置 type="expand" 和 `Scoped slot` 可以开启展开行功能,`el-table-column` 的模板会被渲染成为展开行的内容,展开行可访问的属性与使用自定义列模板时的 `Scoped slot` 相同。
|
2016-11-12 23:08:17 +08:00
|
|
|
|
```html
|
|
|
|
|
<template>
|
|
|
|
|
<el-table
|
2017-02-22 15:02:34 +08:00
|
|
|
|
:data="tableData5"
|
2016-11-12 23:08:17 +08:00
|
|
|
|
style="width: 100%">
|
2016-12-28 18:11:25 +08:00
|
|
|
|
<el-table-column type="expand">
|
2017-10-16 14:07:24 +08:00
|
|
|
|
<template slot-scope="props">
|
2017-02-22 15:02:34 +08:00
|
|
|
|
<el-form label-position="left" inline class="demo-table-expand">
|
|
|
|
|
<el-form-item label="商品名称">
|
|
|
|
|
<span>{{ props.row.name }}</span>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label="所属店铺">
|
|
|
|
|
<span>{{ props.row.shop }}</span>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label="商品 ID">
|
|
|
|
|
<span>{{ props.row.id }}</span>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label="店铺 ID">
|
|
|
|
|
<span>{{ props.row.shopId }}</span>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label="商品分类">
|
|
|
|
|
<span>{{ props.row.category }}</span>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label="店铺地址">
|
|
|
|
|
<span>{{ props.row.address }}</span>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label="商品描述">
|
|
|
|
|
<span>{{ props.row.desc }}</span>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
2016-12-28 18:11:25 +08:00
|
|
|
|
</template>
|
2016-11-12 23:08:17 +08:00
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
2017-02-22 15:02:34 +08:00
|
|
|
|
label="商品 ID"
|
|
|
|
|
prop="id">
|
2016-11-12 23:08:17 +08:00
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
2017-02-22 15:02:34 +08:00
|
|
|
|
label="商品名称"
|
2016-11-12 23:08:17 +08:00
|
|
|
|
prop="name">
|
|
|
|
|
</el-table-column>
|
2017-02-22 15:02:34 +08:00
|
|
|
|
<el-table-column
|
|
|
|
|
label="描述"
|
|
|
|
|
prop="desc">
|
|
|
|
|
</el-table-column>
|
2016-11-12 23:08:17 +08:00
|
|
|
|
</el-table>
|
|
|
|
|
</template>
|
|
|
|
|
|
2017-02-22 15:02:34 +08:00
|
|
|
|
<style>
|
|
|
|
|
.demo-table-expand {
|
|
|
|
|
font-size: 0;
|
|
|
|
|
}
|
|
|
|
|
.demo-table-expand label {
|
|
|
|
|
width: 90px;
|
|
|
|
|
color: #99a9bf;
|
|
|
|
|
}
|
|
|
|
|
.demo-table-expand .el-form-item {
|
|
|
|
|
margin-right: 0;
|
|
|
|
|
margin-bottom: 0;
|
|
|
|
|
width: 50%;
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
|
2016-11-12 23:08:17 +08:00
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
2017-02-22 15:02:34 +08:00
|
|
|
|
tableData5: [{
|
|
|
|
|
id: '12987122',
|
|
|
|
|
name: '好滋好味鸡蛋仔',
|
|
|
|
|
category: '江浙小吃、小吃零食',
|
|
|
|
|
desc: '荷兰优质淡奶,奶香浓而不腻',
|
|
|
|
|
address: '上海市普陀区真北路',
|
|
|
|
|
shop: '王小虎夫妻店',
|
|
|
|
|
shopId: '10333'
|
|
|
|
|
}, {
|
|
|
|
|
id: '12987123',
|
|
|
|
|
name: '好滋好味鸡蛋仔',
|
|
|
|
|
category: '江浙小吃、小吃零食',
|
|
|
|
|
desc: '荷兰优质淡奶,奶香浓而不腻',
|
|
|
|
|
address: '上海市普陀区真北路',
|
|
|
|
|
shop: '王小虎夫妻店',
|
|
|
|
|
shopId: '10333'
|
|
|
|
|
}, {
|
|
|
|
|
id: '12987125',
|
|
|
|
|
name: '好滋好味鸡蛋仔',
|
|
|
|
|
category: '江浙小吃、小吃零食',
|
|
|
|
|
desc: '荷兰优质淡奶,奶香浓而不腻',
|
|
|
|
|
address: '上海市普陀区真北路',
|
|
|
|
|
shop: '王小虎夫妻店',
|
|
|
|
|
shopId: '10333'
|
|
|
|
|
}, {
|
|
|
|
|
id: '12987126',
|
|
|
|
|
name: '好滋好味鸡蛋仔',
|
|
|
|
|
category: '江浙小吃、小吃零食',
|
|
|
|
|
desc: '荷兰优质淡奶,奶香浓而不腻',
|
|
|
|
|
address: '上海市普陀区真北路',
|
|
|
|
|
shop: '王小虎夫妻店',
|
|
|
|
|
shopId: '10333'
|
2016-11-12 23:08:17 +08:00
|
|
|
|
}]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
```
|
|
|
|
|
:::
|
|
|
|
|
|
2017-04-28 15:53:39 +08:00
|
|
|
|
### 表尾合计行
|
|
|
|
|
|
|
|
|
|
若表格展示的是各类数字,可以在表尾显示各列的合计。
|
|
|
|
|
:::demo 将`show-summary`设置为`true`就会在表格尾部展示合计行。默认情况下,对于合计行,第一列不进行数据求合操作,而是显示「合计」二字(可通过`sum-text`配置),其余列会将本列所有数值进行求合操作,并显示出来。当然,你也可以定义自己的合计逻辑。使用`summary-method`并传入一个方法,返回一个数组,这个数组中的各项就会显示在合计行的各列中,具体可以参考本例中的第二个表格。
|
|
|
|
|
```html
|
|
|
|
|
<template>
|
|
|
|
|
<el-table
|
|
|
|
|
:data="tableData6"
|
|
|
|
|
border
|
|
|
|
|
show-summary
|
|
|
|
|
style="width: 100%">
|
|
|
|
|
<el-table-column
|
|
|
|
|
prop="id"
|
|
|
|
|
label="ID"
|
|
|
|
|
width="180">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
|
|
|
|
prop="name"
|
|
|
|
|
label="姓名">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
|
|
|
|
prop="amount1"
|
|
|
|
|
sortable
|
|
|
|
|
label="数值 1">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
|
|
|
|
prop="amount2"
|
|
|
|
|
sortable
|
|
|
|
|
label="数值 2">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
|
|
|
|
prop="amount3"
|
|
|
|
|
sortable
|
|
|
|
|
label="数值 3">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
</el-table>
|
|
|
|
|
|
|
|
|
|
<el-table
|
|
|
|
|
:data="tableData6"
|
|
|
|
|
border
|
|
|
|
|
height="200"
|
|
|
|
|
:summary-method="getSummaries"
|
|
|
|
|
show-summary
|
|
|
|
|
style="width: 100%; margin-top: 20px">
|
|
|
|
|
<el-table-column
|
|
|
|
|
prop="id"
|
|
|
|
|
label="ID"
|
|
|
|
|
width="180">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
|
|
|
|
prop="name"
|
|
|
|
|
label="姓名">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
|
|
|
|
prop="amount1"
|
|
|
|
|
label="数值 1(元)">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
|
|
|
|
prop="amount2"
|
|
|
|
|
label="数值 2(元)">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
|
|
|
|
prop="amount3"
|
|
|
|
|
label="数值 3(元)">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
</el-table>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
tableData6: [{
|
|
|
|
|
id: '12987122',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
amount1: '234',
|
|
|
|
|
amount2: '3.2',
|
|
|
|
|
amount3: 10
|
|
|
|
|
}, {
|
|
|
|
|
id: '12987123',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
amount1: '165',
|
|
|
|
|
amount2: '4.43',
|
|
|
|
|
amount3: 12
|
|
|
|
|
}, {
|
|
|
|
|
id: '12987124',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
amount1: '324',
|
|
|
|
|
amount2: '1.9',
|
|
|
|
|
amount3: 9
|
|
|
|
|
}, {
|
|
|
|
|
id: '12987125',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
amount1: '621',
|
|
|
|
|
amount2: '2.2',
|
|
|
|
|
amount3: 17
|
|
|
|
|
}, {
|
|
|
|
|
id: '12987126',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
amount1: '539',
|
|
|
|
|
amount2: '4.1',
|
|
|
|
|
amount3: 15
|
|
|
|
|
}]
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
getSummaries(param) {
|
|
|
|
|
const { columns, data } = param;
|
|
|
|
|
const sums = [];
|
|
|
|
|
columns.forEach((column, index) => {
|
|
|
|
|
if (index === 0) {
|
|
|
|
|
sums[index] = '总价';
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const values = data.map(item => Number(item[column.property]));
|
|
|
|
|
if (!values.every(value => isNaN(value))) {
|
|
|
|
|
sums[index] = values.reduce((prev, curr) => {
|
|
|
|
|
const value = Number(curr);
|
|
|
|
|
if (!isNaN(value)) {
|
|
|
|
|
return prev + curr;
|
|
|
|
|
} else {
|
|
|
|
|
return prev;
|
|
|
|
|
}
|
|
|
|
|
}, 0);
|
|
|
|
|
sums[index] += ' 元';
|
|
|
|
|
} else {
|
|
|
|
|
sums[index] = 'N/A';
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return sums;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
```
|
|
|
|
|
:::
|
|
|
|
|
|
2017-10-20 11:00:29 +08:00
|
|
|
|
### 合并行或列
|
|
|
|
|
|
|
|
|
|
多行或多列共用一个数据时,可以合并行或列。
|
2017-12-11 10:43:45 +08:00
|
|
|
|
:::demo 通过给`table`传入`span-method`方法可以实现合并行或列,方法的参数是一个对象,里面包含当前行`row`、当前列`column`、当前行号`rowIndex`、当前列号`columnIndex`四个属性。该函数可以返回一个包含两个元素的数组,第一个元素代表`rowspan`,第二个元素代表`colspan`。 也可以返回一个键名为`rowspan`和`colspan`的对象。
|
2017-10-20 11:00:29 +08:00
|
|
|
|
|
|
|
|
|
```html
|
|
|
|
|
<template>
|
|
|
|
|
<div>
|
|
|
|
|
<el-table
|
|
|
|
|
:data="tableData6"
|
|
|
|
|
:span-method="arraySpanMethod"
|
|
|
|
|
border
|
|
|
|
|
style="width: 100%">
|
|
|
|
|
<el-table-column
|
|
|
|
|
prop="id"
|
|
|
|
|
label="ID"
|
|
|
|
|
width="180">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
|
|
|
|
prop="name"
|
|
|
|
|
label="姓名">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
|
|
|
|
prop="amount1"
|
|
|
|
|
sortable
|
|
|
|
|
label="数值 1">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
|
|
|
|
prop="amount2"
|
|
|
|
|
sortable
|
|
|
|
|
label="数值 2">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
|
|
|
|
prop="amount3"
|
|
|
|
|
sortable
|
|
|
|
|
label="数值 3">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
</el-table>
|
|
|
|
|
|
|
|
|
|
<el-table
|
|
|
|
|
:data="tableData6"
|
|
|
|
|
:span-method="objectSpanMethod"
|
|
|
|
|
border
|
|
|
|
|
style="width: 100%; margin-top: 20px">
|
|
|
|
|
<el-table-column
|
|
|
|
|
prop="id"
|
|
|
|
|
label="ID"
|
|
|
|
|
width="180">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
|
|
|
|
prop="name"
|
|
|
|
|
label="姓名">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
|
|
|
|
prop="amount1"
|
|
|
|
|
label="数值 1(元)">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
|
|
|
|
prop="amount2"
|
|
|
|
|
label="数值 2(元)">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
|
|
|
|
prop="amount3"
|
|
|
|
|
label="数值 3(元)">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
</el-table>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
tableData6: [{
|
|
|
|
|
id: '12987122',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
amount1: '234',
|
|
|
|
|
amount2: '3.2',
|
|
|
|
|
amount3: 10
|
|
|
|
|
}, {
|
|
|
|
|
id: '12987123',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
amount1: '165',
|
|
|
|
|
amount2: '4.43',
|
|
|
|
|
amount3: 12
|
|
|
|
|
}, {
|
|
|
|
|
id: '12987124',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
amount1: '324',
|
|
|
|
|
amount2: '1.9',
|
|
|
|
|
amount3: 9
|
|
|
|
|
}, {
|
|
|
|
|
id: '12987125',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
amount1: '621',
|
|
|
|
|
amount2: '2.2',
|
|
|
|
|
amount3: 17
|
|
|
|
|
}, {
|
|
|
|
|
id: '12987126',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
amount1: '539',
|
|
|
|
|
amount2: '4.1',
|
|
|
|
|
amount3: 15
|
|
|
|
|
}]
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
arraySpanMethod({ row, column, rowIndex, columnIndex }) {
|
|
|
|
|
if (rowIndex % 2 === 0) {
|
|
|
|
|
if (columnIndex === 0) {
|
|
|
|
|
return [1, 2];
|
|
|
|
|
} else if (columnIndex === 1) {
|
|
|
|
|
return [0, 0];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
objectSpanMethod({ row, column, rowIndex, columnIndex }) {
|
|
|
|
|
if (columnIndex === 0) {
|
|
|
|
|
if (rowIndex % 2 === 0) {
|
|
|
|
|
return {
|
|
|
|
|
rowspan: 2,
|
|
|
|
|
colspan: 1
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
return {
|
|
|
|
|
rowspan: 0,
|
|
|
|
|
colspan: 0
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
```
|
|
|
|
|
:::
|
|
|
|
|
|
2017-10-25 15:35:12 +08:00
|
|
|
|
### 自定义索引
|
|
|
|
|
|
|
|
|
|
自定义 `type=index` 列的行号。
|
|
|
|
|
:::demo 通过给 `type=index` 的列传入 `index` 属性,可以自定义索引。该属性传入数字时,将作为索引的起始值。也可以传入一个方法,它提供当前行的行号(从 `0` 开始)作为参数,返回值将作为索引展示。
|
|
|
|
|
|
|
|
|
|
```html
|
|
|
|
|
<template>
|
|
|
|
|
<el-table
|
|
|
|
|
:data="tableData"
|
|
|
|
|
style="width: 100%">
|
|
|
|
|
<el-table-column
|
|
|
|
|
type="index"
|
|
|
|
|
:index="indexMethod">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
|
|
|
|
prop="date"
|
|
|
|
|
label="日期"
|
|
|
|
|
width="180">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
|
|
|
|
prop="name"
|
|
|
|
|
label="姓名"
|
|
|
|
|
width="180">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
|
|
|
|
prop="address"
|
|
|
|
|
label="地址">
|
|
|
|
|
</el-table-column>
|
|
|
|
|
</el-table>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
2017-10-25 18:31:51 +08:00
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
tableData: [{
|
|
|
|
|
date: '2016-05-03',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
zip: 200333,
|
|
|
|
|
tag: '家'
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-02',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
zip: 200333,
|
|
|
|
|
tag: '公司'
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-04',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
zip: 200333,
|
|
|
|
|
tag: '家'
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-01',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
province: '上海',
|
|
|
|
|
city: '普陀区',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄',
|
|
|
|
|
zip: 200333,
|
|
|
|
|
tag: '公司'
|
|
|
|
|
}],
|
|
|
|
|
}
|
|
|
|
|
},
|
2017-10-25 15:35:12 +08:00
|
|
|
|
methods: {
|
|
|
|
|
indexMethod(index) {
|
|
|
|
|
return index * 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
</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-11-18 15:59:00 +08:00
|
|
|
|
| height | Table 的高度,默认为自动高度。如果 height 为 number 类型,单位 px;如果 height 为 string 类型,则 Table 的高度受控于外部样式。 | string/number | — | — |
|
2017-03-29 11:59:12 +08:00
|
|
|
|
| max-height | Table 的最大高度 | string/number | — | — |
|
2016-09-02 13:56:47 +08:00
|
|
|
|
| stripe | 是否为斑马纹 table | boolean | — | false |
|
|
|
|
|
| border | 是否带有纵向边框 | boolean | — | false |
|
2017-10-25 11:58:58 +08:00
|
|
|
|
| size | Table 的尺寸 | string | medium / small / mini | — |
|
2016-09-29 16:39:53 +08:00
|
|
|
|
| fit | 列的宽度是否自撑开 | boolean | — | true |
|
2016-12-29 20:53:33 +08:00
|
|
|
|
| show-header | 是否显示表头 | boolean | — | true |
|
2016-11-13 11:58:45 +08:00
|
|
|
|
| highlight-current-row | 是否要高亮当前行 | boolean | — | false |
|
2016-12-29 20:53:33 +08:00
|
|
|
|
| current-row-key | 当前行的 key,只写属性 | String,Number | — | — |
|
2017-10-25 15:35:12 +08:00
|
|
|
|
| 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 | — | — |
|
2017-12-18 17:38:51 +08:00
|
|
|
|
| cell-style | 单元格的 style 的回调方法,也可以使用一个固定的 Object 为所有单元格设置一样的 Style。 | Function({row, column, rowIndex, columnIndex})/Object | — | — |
|
2017-10-25 15:35:12 +08:00
|
|
|
|
| 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 | — | — |
|
2017-07-02 20:24:57 +08:00
|
|
|
|
| row-key | 行数据的 Key,用来优化 Table 的渲染;在使用 reserve-selection 功能的情况下,该属性是必填的。类型为 String 时,支持多层访问:`user.info.id`,但不支持 `user.info[0].id`,此种情况请使用 `Function`。 | Function(row)/String | — | — |
|
2016-12-29 20:53:33 +08:00
|
|
|
|
| empty-text | 空数据时显示的文本内容,也可以通过 `slot="empty"` 设置 | String | — | 暂无数据 |
|
|
|
|
|
| default-expand-all | 是否默认展开所有行,当 Table 中存在 type="expand" 的 Column 的时候有效 | Boolean | — | false |
|
|
|
|
|
| expand-row-keys | 可以通过该属性设置 Table 目前的展开行,需要设置 row-key 属性才能使用,该属性为展开行的 keys 数组。| Array | — | |
|
2017-01-14 14:51:44 +08:00
|
|
|
|
| default-sort | 默认的排序列的prop和顺序。它的`prop`属性指定默认的排序的列,`order`指定默认排序的顺序| Object | `order`: ascending, descending | 如果只指定了`prop`, 没有指定`order`, 则默认顺序是ascending |
|
2017-03-29 11:59:12 +08:00
|
|
|
|
| tooltip-effect | tooltip `effect` 属性 | String | dark/light | | dark |
|
2017-04-28 15:53:39 +08:00
|
|
|
|
| show-summary | 是否在表尾显示合计行 | Boolean | — | false |
|
|
|
|
|
| sum-text | 合计行第一列的文本 | String | — | 合计 |
|
|
|
|
|
| summary-method | 自定义的合计计算方法 | Function({ columns, data }) | — | — |
|
2017-10-20 11:00:29 +08:00
|
|
|
|
| span-method | 合并行或列的计算方法 | Function({ row, column, rowIndex, columnIndex }) | — | — |
|
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 |
|
2017-02-23 11:30:55 +08:00
|
|
|
|
| cell-dblclick | 当某个单元格被双击击时会触发该事件 | row, column, cell, event |
|
2016-12-17 14:00:35 +08:00
|
|
|
|
| row-click | 当某一行被点击时会触发该事件 | row, event, column |
|
2016-12-14 13:42:56 +08:00
|
|
|
|
| row-contextmenu | 当某一行被鼠标右键点击时会触发该事件 | row, event |
|
2016-12-02 17:11:04 +08:00
|
|
|
|
| row-dblclick | 当某一行被双击时会触发该事件 | row, event |
|
2016-11-18 15:59:00 +08:00
|
|
|
|
| header-click | 当某一列的表头被点击时会触发该事件 | column, event |
|
2018-01-29 18:42:05 +08:00
|
|
|
|
| header-contextmenu | 当某一当用户右击列标题时触发 | column, event |
|
2016-10-28 01:24:13 +08:00
|
|
|
|
| sort-change | 当表格的排序条件发生变化的时候会触发该事件 | { column, prop, order } |
|
2016-12-20 18:21:15 +08:00
|
|
|
|
| filter-change | 当表格的筛选条件发生变化的时候会触发该事件,参数的值是一个对象,对象的 key 是 column 的 columnKey,对应的 value 为用户选择的筛选条件的数组。 | filters |
|
2016-11-13 11:58:45 +08:00
|
|
|
|
| current-change | 当表格的当前行发生变化的时候会触发该事件,如果要高亮当前行,请打开表格的 highlight-current-row 属性 | currentRow, oldCurrentRow |
|
2017-02-23 13:09:25 +08:00
|
|
|
|
| header-dragend | 当拖动表头改变了列的宽度的时候会触发该事件 | newWidth, oldWidth, column, event |
|
2017-10-25 18:31:51 +08:00
|
|
|
|
| expand-change | 当用户对某一行展开或者关闭的时候会触发该事件 | row, expandedRows |
|
2016-10-19 18:53:31 +08:00
|
|
|
|
|
|
|
|
|
### Table Methods
|
|
|
|
|
| 方法名 | 说明 | 参数 |
|
|
|
|
|
| ---- | ---- | ---- |
|
2017-04-22 01:11:32 +08:00
|
|
|
|
| clearSelection | 用于多选表格,清空用户的选择,当使用 reserve-selection 功能的时候,可能会需要使用此方法 | selection |
|
|
|
|
|
| toggleRowSelection | 用于多选表格,切换某一行的选中状态,如果使用了第二个参数,则是设置这一行选中与否(selected 为 true 则选中) | row, selected |
|
2017-10-25 18:31:51 +08:00
|
|
|
|
| toggleRowExpansion | 用于可展开表格,切换某一行的展开状态,如果使用了第二个参数,则是设置这一行展开与否(expanded 为 true 则展开) | row, expanded |
|
2017-04-22 01:11:32 +08:00
|
|
|
|
| setCurrentRow | 用于单选表格,设定某一行为选中行,如果调用时不加参数,则会取消目前高亮行的选中状态。 | row |
|
2017-10-23 17:50:25 +08:00
|
|
|
|
| clearSort | 用于清空排序条件,数据会恢复成未排序的状态 | — |
|
|
|
|
|
| clearFilter | 用于清空过滤条件,数据会恢复成未过滤的状态 | — |
|
2017-11-17 12:22:55 +08:00
|
|
|
|
| doLayout | 对 Table 进行重新布局。当 Table 或其祖先元素由隐藏切换为显示时,可能需要调用此方法 | — |
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2017-04-28 15:53:39 +08:00
|
|
|
|
### Table Slot
|
|
|
|
|
| name | 说明 |
|
|
|
|
|
|------|--------|
|
2017-10-20 11:00:29 +08:00
|
|
|
|
| append | 插入至表格最后一行之后的内容,如果需要对表格的内容进行无限滚动操作,可能需要用到这个 slot。若表格有合计行,该 slot 会位于合计行之上。 |
|
2017-04-28 15:53:39 +08:00
|
|
|
|
|
2016-08-26 19:46:45 +08:00
|
|
|
|
### Table-column Attributes
|
2016-07-27 14:15:02 +08:00
|
|
|
|
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|
|
|
|
|
|---------- |-------------- |---------- |-------------------------------- |-------- |
|
2017-10-25 15:35:12 +08:00
|
|
|
|
| type | 对应列的类型。如果设置了 `selection` 则显示多选框;如果设置了 `index` 则显示该行的索引(从 1 开始计算);如果设置了 `expand` 则显示为一个可展开的按钮 | string | selection/index/expand | — |
|
|
|
|
|
| index | 如果设置了 `type=index`,可以通过传递 `index` 属性来自定义索引 | string, Function(index) | - | - |
|
2016-12-29 20:53:33 +08:00
|
|
|
|
| column-key | column 的 key,如果需要使用 filter-change 事件,则需要此属性标识是哪个 column 的筛选条件 | string | — | — |
|
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-11-13 11:58:45 +08:00
|
|
|
|
| fixed | 列是否固定在左侧或者右侧,true 表示固定在左侧 | string, boolean | true, left, right | — |
|
|
|
|
|
| render-header | 列标题 Label 区域渲染使用的 Function | Function(h, { column, $index }) | — | — |
|
2016-10-28 01:24:13 +08:00
|
|
|
|
| sortable | 对应列是否可以排序,如果设置为 'custom',则代表用户希望远程排序,需要监听 Table 的 sort-change 事件 | boolean, string | true, false, 'custom' | false |
|
2017-10-20 16:03:53 +08:00
|
|
|
|
| sort-method | 对数据进行排序的时候使用的方法,仅当 sortable 设置为 true 的时候有效,需返回一个数字,和 Array.sort 表现一致 | Function(a, b) | — | — |
|
2017-10-31 12:16:55 +08:00
|
|
|
|
| sort-by | 指定数据按照哪个属性进行排序,仅当 sortable 设置为 true 且没有设置 sort-method 的时候有效。如果 sort-by 为数组,则先按照第 1 个属性排序,如果第 1 个相等,再按照第 2 个排序,以此类推。 | String/Array/Function(row, index) | — | — |
|
2016-11-13 11:58:45 +08:00
|
|
|
|
| resizable | 对应列是否可以通过拖动改变宽度(需要在 el-table 上设置 border 属性为真) | boolean | — | true |
|
2017-07-15 17:14:40 +08:00
|
|
|
|
| formatter | 用来格式化内容 | Function(row, column, cellValue) | — | — |
|
2016-11-13 11:58:45 +08:00
|
|
|
|
| show-overflow-tooltip | 当内容过长被隐藏时显示 tooltip | Boolean | — | false |
|
2016-12-22 17:29:26 +08:00
|
|
|
|
| align | 对齐方式 | String | left/center/right | left |
|
|
|
|
|
| header-align | 表头对齐方式,若不设置该项,则使用表格的对齐方式 | String | left/center/right | — |
|
2016-11-13 14:39:24 +08:00
|
|
|
|
| class-name | 列的 className | string | — | — |
|
2017-03-09 18:04:20 +08:00
|
|
|
|
| label-class-name | 当前列标题的自定义类名 | string | — | — |
|
2016-11-13 11:58:45 +08:00
|
|
|
|
| selectable | 仅对 type=selection 的列有效,类型为 Function,Function 的返回值用来决定这一行的 CheckBox 是否可以勾选 | Function(row, index) | — | — |
|
|
|
|
|
| reserve-selection | 仅对 type=selection 的列有效,类型为 Boolean,为 true 则代表会保留之前数据的选项,需要配合 Table 的 clearSelection 方法使用。 | Boolean | — | false |
|
2016-10-27 21:45:21 +08:00
|
|
|
|
| filters | 数据过滤的选项,数组格式,数组中的元素需要有 text 和 value 属性。 | Array[{ text, value }] | — | — |
|
2017-05-03 15:23:38 +08:00
|
|
|
|
| filter-placement | 过滤弹出框的定位 | String | 与 Tooltip 的 `placement` 属性相同 | — |
|
2016-10-27 21:45:21 +08:00
|
|
|
|
| filter-multiple | 数据过滤的选项是否多选 | Boolean | — | true |
|
2018-01-15 12:25:53 +08:00
|
|
|
|
| filter-method | 数据过滤使用的方法,如果是多选的筛选项,对每一条数据会执行多次,任意一次返回 true 就会显示。 | Function(value, row, column) | — | — |
|
2017-01-05 12:38:39 +08:00
|
|
|
|
| filtered-value | 选中的数据过滤项,如果需要自定义表头过滤的渲染方式,可能会需要此属性。 | Array | — | — |
|