-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVPivottableBodyRows.vue
97 lines (87 loc) · 2.32 KB
/
VPivottableBodyRows.vue
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
<template>
<tr v-for="(rowKey, i) in rowKeys" :key="`rowKeyRow${i}`">
<template v-for="(text, j) in rowKey" :key="`rowLabel${i}-${j}`">
<th
v-if="spanSize(rowKeys, i, j) !== -1"
class="pvtRowLabel"
:rowSpan="spanSize(rowKeys, i, j)"
:colSpan="j === rowAttrs.length - 1 && colAttrs.length !== 0 ? 2 : 1"
>
{{ text }}
</th>
</template>
<td
v-for="(colKey, j) in colKeys"
:key="`pvtVal${i}-${j}`"
class="pvVal"
:style="getValueCellStyle(rowKey, colKey)"
@click="handleCellClick(getAggregator(rowKey, colKey).value(), rowKey, colKey)"
>
{{ getAggregator(rowKey, colKey).format(getAggregator(rowKey, colKey).value()) }}
</td>
<td
v-if="rowTotal"
class="pvtTotal"
:style="getRowTotalStyle(rowKey)"
@click="handleCellClick(getAggregator(rowKey, []).value(), rowKey, [])"
>
{{ getAggregator(rowKey, []).format(getAggregator(rowKey, []).value()) }}
</td>
</tr>
</template>
<script setup>
import { useProvidePivotData } from '@/composables/useProvidePivotData'
const props = defineProps({
rowKeys: {
type: Array,
required: true
},
colKeys: {
type: Array,
required: true
},
rowTotal: {
type: Boolean,
required: true
},
tableOptions: {
type: Object,
required: true
}
})
const {
pivotData,
spanSize,
valueCellColors,
colTotalColors,
rowAttrs,
colAttrs,
getAggregator
} = useProvidePivotData()
const getValueCellStyle = (rowKey, colKey) => {
const value = getAggregator(rowKey, colKey).value()
return valueCellColors(rowKey, colKey, value)
}
const getRowTotalStyle = (rowKey) => {
const value = getAggregator(rowKey, []).value()
return colTotalColors(value)
}
const handleCellClick = (value, rowValues, colValues) => {
if (props.tableOptions?.clickCallback) {
const filters = {}
// Add column filters
colAttrs.value.forEach((attr, i) => {
if (colValues[i] !== undefined && colValues[i] !== null) {
filters[attr] = colValues[i]
}
})
// Add row filters
rowAttrs.value.forEach((attr, i) => {
if (rowValues[i] !== undefined && rowValues[i] !== null) {
filters[attr] = rowValues[i]
}
})
props.tableOptions.clickCallback(event, value, filters, pivotData.value)
}
}
</script>