FooterTable.vue
2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<template>
<div class="p-4">
<BasicTable @register="registerTable" />
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { BasicTable, useTable } from '/@/components/Table';
import { BasicColumn } from '/@/components/Table/src/types/table';
import { demoListApi } from '/@/api/demo/table';
export default defineComponent({
components: { BasicTable },
setup() {
function handleSummary(tableData: Recordable[]) {
const totalAge = tableData.reduce((prev, next) => {
prev += next.age;
return prev;
}, 0);
const totalScore = tableData.reduce((prev, next) => {
prev += next.score;
return prev;
}, 0);
return [
{
_row: '合计',
_index: '平均值',
age: Math.round(totalAge / tableData.length),
score: Math.round(totalScore / tableData.length),
},
{
_row: '合计',
_index: '平均值',
age: totalAge,
score: totalScore,
},
];
}
const getBasicColumns = (): BasicColumn[] => {
return [
{
title: 'ID',
dataIndex: 'id',
fixed: 'left',
width: 200,
},
{
title: '姓名',
dataIndex: 'name',
width: 150,
filters: [
{ text: 'Male', value: 'male' },
{ text: 'Female', value: 'female' },
],
},
{
title: '年龄',
dataIndex: 'age',
width: 100,
},
{
title: '得分',
dataIndex: 'score',
width: 100,
resizable: true,
},
{
title: '地址',
dataIndex: 'address',
width: 300,
},
{
title: '编号',
dataIndex: 'no',
width: 150,
sorter: true,
defaultHidden: true,
},
{
title: '开始时间',
width: 150,
sorter: true,
dataIndex: 'beginTime',
},
{
title: '结束时间',
width: 150,
sorter: true,
dataIndex: 'endTime',
},
];
};
const [registerTable] = useTable({
title: '表尾行合计示例',
api: demoListApi,
rowSelection: { type: 'checkbox' },
columns: getBasicColumns(),
// showSummary: true使用的是自定义的表尾行合计方式,如果不设置或者为false使用的antd
showSummary: true,
summaryFunc: handleSummary,
scroll: { x: 1000 },
canResize: false,
});
return {
registerTable,
};
},
});
</script>