|
1 | 1 | <template>
|
2 |
| - <tr> |
3 |
| - <th v-for="(text, j) in rowKey" :key="`rowKeyLabel${index}-${j}`" |
4 |
| - class="pvtRowLabel" |
5 |
| - :rowspan="spanSize(rowKeys, index, j)" |
6 |
| - :colspan="j === rowAttrs.length - 1 && colAttrs.length !== 0 ? 2 : 1" |
| 2 | + <tr v-for="(rowKey, i) in rowKeys" :key="`rowKeyRow${i}`"> |
| 3 | + <template v-for="(text, j) in rowKey" :key="`rowLabel${i}-${j}`"> |
| 4 | + <th |
| 5 | + v-if="spanSize(rowKeys, i, j) !== -1" |
| 6 | + class="pvtRowLabel" |
| 7 | + :rowSpan="spanSize(rowKeys, i, j)" |
| 8 | + :colSpan="j === rowAttrs.length - 1 && colAttrs.length !== 0 ? 2 : 1" |
| 9 | + > |
| 10 | + {{ text }} |
| 11 | + </th> |
| 12 | + </template> |
| 13 | + <td |
| 14 | + v-for="(colKey, j) in colKeys" |
| 15 | + :key="`pvtVal${i}-${j}`" |
| 16 | + class="pvVal" |
| 17 | + :style="getValueCellStyle(rowKey, colKey)" |
| 18 | + @click="handleCellClick(getAggregator(rowKey, colKey).value(), rowKey, colKey)" |
7 | 19 | >
|
8 |
| - {{ text }} |
9 |
| - </th> |
10 |
| - <td v-for="(colKey, j) in colKeys" :key="`pvtVal${index}-${j}`" |
11 |
| - :class="['pvVal']" |
12 |
| - > |
13 |
| - {{ getValue(rowKey, colKey) }} |
| 20 | + {{ getAggregator(rowKey, colKey).format(getAggregator(rowKey, colKey).value()) }} |
14 | 21 | </td>
|
15 |
| - <td v-if="rowTotal" |
| 22 | + <td |
| 23 | + v-if="rowTotal" |
16 | 24 | class="pvtTotal"
|
| 25 | + :style="getRowTotalStyle(rowKey)" |
| 26 | + @click="handleCellClick(getAggregator(rowKey, []).value(), rowKey, [])" |
17 | 27 | >
|
18 |
| - {{ getTotalValue(rowKey, []) }} |
| 28 | + {{ getAggregator(rowKey, []).format(getAggregator(rowKey, []).value()) }} |
19 | 29 | </td>
|
20 | 30 | </tr>
|
21 | 31 | </template>
|
22 | 32 |
|
23 | 33 | <script setup>
|
24 |
| -import { spanSize } from '../../helper' |
| 34 | +
|
| 35 | +import { useProvidePivotData } from '@/composables/useProvidePivotData' |
| 36 | +
|
25 | 37 | const props = defineProps({
|
26 |
| - pivotData: Object, |
27 |
| - index: Number, |
28 |
| - rowKeys: Array, |
29 |
| - rowKey: Array, |
30 |
| - colKeys: Array, |
31 |
| - rowAttrs: Array, |
32 |
| - colAttrs: Array, |
33 |
| - tableOptions: Object, |
34 |
| - rowTotal: Boolean |
| 38 | + rowKeys: { |
| 39 | + type: Array, |
| 40 | + required: true |
| 41 | + }, |
| 42 | + colKeys: { |
| 43 | + type: Array, |
| 44 | + required: true |
| 45 | + }, |
| 46 | + rowTotal: { |
| 47 | + type: Boolean, |
| 48 | + required: true |
| 49 | + }, |
| 50 | + tableOptions: { |
| 51 | + type: Object, |
| 52 | + required: true |
| 53 | + } |
35 | 54 | })
|
36 |
| -const getValue = (rowKey, colKey) => { |
37 |
| - const aggregator = props.pivotData.getAggregator(rowKey, colKey) |
38 |
| - return aggregator.format(aggregator.value()) |
| 55 | +
|
| 56 | +const { |
| 57 | + pivotData, |
| 58 | + spanSize, |
| 59 | + valueCellColors, |
| 60 | + colTotalColors, |
| 61 | + rowAttrs, |
| 62 | + colAttrs, |
| 63 | + getAggregator |
| 64 | +} = useProvidePivotData() |
| 65 | +
|
| 66 | +const getValueCellStyle = (rowKey, colKey) => { |
| 67 | + const value = getAggregator(rowKey, colKey).value() |
| 68 | + return valueCellColors(rowKey, colKey, value) |
39 | 69 | }
|
40 |
| -const getTotalValue = (rowKey, colKey) => { |
41 |
| - const totalAggregator = props.pivotData.getAggregator(rowKey, colKey) |
42 |
| - return totalAggregator.format(totalAggregator.value()) |
| 70 | +
|
| 71 | +const getRowTotalStyle = (rowKey) => { |
| 72 | + const value = getAggregator(rowKey, []).value() |
| 73 | + return colTotalColors(value) |
43 | 74 | }
|
44 | 75 |
|
45 |
| -</script> |
| 76 | +const handleCellClick = (value, rowValues, colValues) => { |
| 77 | + if (props.tableOptions?.clickCallback) { |
| 78 | + const filters = {} |
| 79 | +
|
| 80 | + // Add column filters |
| 81 | + colAttrs.value.forEach((attr, i) => { |
| 82 | + if (colValues[i] !== undefined && colValues[i] !== null) { |
| 83 | + filters[attr] = colValues[i] |
| 84 | + } |
| 85 | + }) |
46 | 86 |
|
47 |
| -<style lang="scss" scoped> |
| 87 | + // Add row filters |
| 88 | + rowAttrs.value.forEach((attr, i) => { |
| 89 | + if (rowValues[i] !== undefined && rowValues[i] !== null) { |
| 90 | + filters[attr] = rowValues[i] |
| 91 | + } |
| 92 | + }) |
48 | 93 |
|
49 |
| -</style> |
| 94 | + props.tableOptions.clickCallback(event, value, filters, pivotData.value) |
| 95 | + } |
| 96 | +} |
| 97 | +</script> |
0 commit comments