Skip to content

Commit dbbd6e1

Browse files
author
黄书伟
committed
add doc
1 parent 35083c7 commit dbbd6e1

File tree

2 files changed

+135
-0
lines changed

2 files changed

+135
-0
lines changed
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
:::demo 通过设置 `footer` 数组对象给 table 添加汇总信息,footer 汇总信息可以设置多行,每一个子数组代表一行汇总信息 <br> **注意**:由于汇总信息格式不定,有求和、平均值、最大值等等,以及保留位数不定等问题。所以汇总信息由调用者提供!
2+
```html
3+
<template>
4+
<div>
5+
<v-table
6+
is-horizontal-resize
7+
style="width:100%"
8+
:height="260"
9+
:columns="columns"
10+
:table-data="tableData"
11+
:footer-cell-class-name="setFooterCellClass"
12+
:footer="footer"
13+
:footer-row-height="40"
14+
></v-table>
15+
</div>
16+
</template>
17+
18+
<style>
19+
.footer-cell-class-name-title {
20+
background-color: #f60;
21+
color: #fff;
22+
}
23+
24+
.footer-cell-class-name-normal {
25+
26+
color: red;
27+
}
28+
29+
</style>
30+
31+
<script>
32+
33+
export default{
34+
data() {
35+
return {
36+
tableData: [
37+
{"name": "赵伟", "amount1": "2", "amount2": "3", "amount3": "上海市黄浦区金陵东路569号17楼"},
38+
{"name": "李伟", "amount1": "5", "amount2": "4", "amount3": "上海市奉贤区南桥镇立新路12号2楼"},
39+
{"name": "孙伟", "amount1": "3", "amount2": "9", "amount3": "上海市崇明县城桥镇八一路739号"},
40+
{"name": "周伟", "amount1": "6", "amount2": "10", "amount3": "上海市青浦区青浦镇章浜路24号"},
41+
{"name": "吴伟", "amount1": "1", "amount2": "12", "amount3": "上海市松江区乐都西路867-871号"}
42+
],
43+
columns: [
44+
{field: 'name',title: '姓名',width: 100,titleAlign: 'center',columnAlign: 'center',isFrozen: true},
45+
{field: 'amount1',title: '数值1',width: 260,titleAlign: 'center',columnAlign: 'center',isResize: true},
46+
{field: 'amount2',title: '数值2',width: 330,titleAlign: 'center',columnAlign: 'center',isResize: true},
47+
{field: 'amount3',title: '数值3',width: 308,titleAlign: 'center',columnAlign: 'left',isResize: true}
48+
],
49+
footer: []
50+
/* 下面的数据结构
51+
footer: [
52+
['最小值',1,3,'-'],
53+
['求和',17,38,'-']
54+
]
55+
*/
56+
}
57+
},
58+
59+
methods: {
60+
61+
setFooterData(){
62+
63+
let result = [],
64+
amounts1 = this.tableData.map(item => {
65+
return item.amount1
66+
}),
67+
amounts2 = this.tableData.map(item => {
68+
return item.amount2
69+
});
70+
71+
let minVal = ['最小值'];
72+
minVal.push(Math.min.apply(null, amounts1));
73+
minVal.push(Math.min.apply(null, amounts2));
74+
minVal.push('-');
75+
76+
77+
let sumVal = ['求和'];
78+
sumVal.push(
79+
amounts1.reduce((prev, curr) => {
80+
81+
return parseInt(prev) + parseInt(curr);
82+
}, 0)
83+
)
84+
85+
sumVal.push(
86+
amounts2.reduce((prev, curr) => {
87+
88+
return parseInt(prev) + parseInt(curr);
89+
}, 0)
90+
)
91+
92+
sumVal.push('-');
93+
94+
95+
result.push(minVal);
96+
result.push(sumVal);
97+
98+
this.footer = result;
99+
},
100+
101+
// 设置 footer-cell-class
102+
setFooterCellClass(rowIndex, colIndex, value){
103+
104+
if (colIndex === 0) {
105+
106+
return 'footer-cell-class-name-title'
107+
} else {
108+
109+
return 'footer-cell-class-name-normal'
110+
}
111+
}
112+
113+
},
114+
115+
created(){
116+
117+
this.setFooterData();
118+
}
119+
}
120+
</script>
121+
```
122+
:::

examples/doc/table/main.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@
7575
</div>
7676
</div>
7777

78+
<div class="mt30">
79+
<h3>footer 汇总功能</h3>
80+
81+
<div class="mt30">
82+
<anchor id="table-footer-summary" label="footer 汇总功能" h4 ></anchor>
83+
<footer-summary></footer-summary>
84+
</div>
85+
</div>
86+
7887
<div class="mt30">
7988
<h3>固定列、固定表头、复杂表头</h3>
8089

@@ -177,6 +186,8 @@
177186
178187
import combinedPaging from './combinedPaging.md'
179188
189+
import footerSummary from './footer-summary.md'
190+
180191
181192
import api from './api.md'
182193
@@ -212,6 +223,8 @@
212223
213224
combinedPaging,
214225
226+
footerSummary,
227+
215228
api
216229
},
217230
data() {

0 commit comments

Comments
 (0)