Skip to content

Feat/#14 fix table renderer #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 15, 2025
9 changes: 8 additions & 1 deletion src/components/pivottable-ui/VPivottableUi.vue
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ import VDragAndDropCell from './VDragAndDropCell.vue'
import { VPivottable } from '@/'
import { computed, ref, toRefs, watch } from 'vue'
import { usePropsState, useMaterializeInput } from '@/composables'
import TableRenderer from '../pivottable/renderer/index'
import TableRenderer from '../pivottable/renderer'

const props = defineProps({
...defaultProps,
Expand Down Expand Up @@ -224,6 +224,13 @@ const onUpdateValueFilter = ({ attribute, valueFilter }) => {
}
const onUpdateRendererName = rendererName => {
updateState('rendererName', rendererName)
if (rendererName === 'Table Heatmap') {
updateState('heatmapMode', 'full')
} else if (rendererName === 'Table Row Heatmap') {
updateState('heatmapMode', 'row')
} else if (rendererName === 'Table Col Heatmap') {
updateState('heatmapMode', 'col')
}
}
const onUpdateAggregatorName = aggregatorName => {
updateState('aggregatorName', aggregatorName)
Expand Down
6 changes: 1 addition & 5 deletions src/components/pivottable/VPivottable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<component
:is="rendererComponent"
v-bind="props"
></component>
/>
</template>

<script setup>
Expand All @@ -19,7 +19,3 @@ const props = defineProps({
const rendererComponent = computed(() => props.rendererItems[props.rendererName] || TableRenderer.Table)

</script>

<style lang="scss" scoped>

</style>
54 changes: 41 additions & 13 deletions src/components/pivottable/VPivottableBody.vue
Original file line number Diff line number Diff line change
@@ -1,29 +1,57 @@
<template>
<tbody>
<tbody v-if="pivotData">
<VPivottableBodyRows
v-for="(rowKey, i) in rowKeys"
:key="`rowKeyRow${i}`"
:pivotData="pivotData"
:index="i"
:rowKeys="rowKeys"
:rowKey="rowKey"
:colKeys="colKeys"
:rowTotal="rowTotal"
:tableOptions="tableOptions"
/>
<VPivottableBodyRowsTotalRow
:colTotal="colTotal"
:rowTotal="rowTotal"
:rowAttrs="rowAttrs"
:colAttrs="colAttrs"
:colKeys="colKeys"
:localeStrings="localeStrings"
:tableOptions="tableOptions"
:rowTotal="rowTotal"
/>
</tbody>
</template>

<script setup>
import { useProvidePivotData } from '@/composables/useProvidePivotData'
import VPivottableBodyRows from './VPivottableBodyRows.vue'
import { usePivotData } from '@/composables/usePivotData'
import VPivottableBodyRowsTotalRow from './VPivottableBodyRowsTotalRow.vue'

const { pivotData, rowKeys, colKeys, rowAttrs, colAttrs } = usePivotData()
const { rowTotal, tableOptions } = defineProps(['rowTotal', 'tableOptions'])
</script>
defineProps({
rowTotal: {
type: Boolean,
default: true
},
colTotal: {
type: Boolean,
default: true
},
localeStrings: {
type: Object,
default: () => ({
totals: 'Totals'
})
},
tableOptions: {
type: Object,
default: () => ({
clickCallback: null
})
}
})

<style lang="scss" scoped>
const {
pivotData,
rowKeys,
colKeys,
rowAttrs,
colAttrs
} = useProvidePivotData()

</style>
</script>
112 changes: 80 additions & 32 deletions src/components/pivottable/VPivottableBodyRows.vue
Original file line number Diff line number Diff line change
@@ -1,49 +1,97 @@
<template>
<tr>
<th v-for="(text, j) in rowKey" :key="`rowKeyLabel${index}-${j}`"
class="pvtRowLabel"
:rowspan="spanSize(rowKeys, index, j)"
:colspan="j === rowAttrs.length - 1 && colAttrs.length !== 0 ? 2 : 1"
<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)"
>
{{ text }}
</th>
<td v-for="(colKey, j) in colKeys" :key="`pvtVal${index}-${j}`"
:class="['pvVal']"
>
{{ getValue(rowKey, colKey) }}
{{ getAggregator(rowKey, colKey).format(getAggregator(rowKey, colKey).value()) }}
</td>
<td v-if="rowTotal"
<td
v-if="rowTotal"
class="pvtTotal"
:style="getRowTotalStyle(rowKey)"
@click="handleCellClick(getAggregator(rowKey, []).value(), rowKey, [])"
>
{{ getTotalValue(rowKey, []) }}
{{ getAggregator(rowKey, []).format(getAggregator(rowKey, []).value()) }}
</td>
</tr>
</template>

<script setup>
import { spanSize } from '../../helper'

import { useProvidePivotData } from '@/composables/useProvidePivotData'

const props = defineProps({
pivotData: Object,
index: Number,
rowKeys: Array,
rowKey: Array,
colKeys: Array,
rowAttrs: Array,
colAttrs: Array,
tableOptions: Object,
rowTotal: Boolean
rowKeys: {
type: Array,
required: true
},
colKeys: {
type: Array,
required: true
},
rowTotal: {
type: Boolean,
required: true
},
tableOptions: {
type: Object,
required: true
}
})
const getValue = (rowKey, colKey) => {
const aggregator = props.pivotData.getAggregator(rowKey, colKey)
return aggregator.format(aggregator.value())

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 getTotalValue = (rowKey, colKey) => {
const totalAggregator = props.pivotData.getAggregator(rowKey, colKey)
return totalAggregator.format(totalAggregator.value())

const getRowTotalStyle = (rowKey) => {
const value = getAggregator(rowKey, []).value()
return colTotalColors(value)
}

</script>
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]
}
})

<style lang="scss" scoped>
// Add row filters
rowAttrs.value.forEach((attr, i) => {
if (rowValues[i] !== undefined && rowValues[i] !== null) {
filters[attr] = rowValues[i]
}
})

</style>
props.tableOptions.clickCallback(event, value, filters, pivotData.value)
}
}
</script>
90 changes: 90 additions & 0 deletions src/components/pivottable/VPivottableBodyRowsTotalRow.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<template>
<tr v-if="colTotal">
<th
class="pvtTotalLabel"
:colSpan="rowAttrs.length + (colAttrs.length === 0 ? 0 : 1)"
>
{{ localeStrings.totals }}
</th>
<td
v-for="(colKey, i) in colKeys"
:key="`total${i}`"
class="pvtTotal"
:style="getColTotalStyle(colKey)"
@click="handleCellClick(getAggregator([], colKey).value(), [], colKey)"
>
{{ getAggregator([], colKey).format(getAggregator([], colKey).value()) }}
</td>
<td
v-if="rowTotal"
class="pvtGrandTotal"
@click="handleCellClick(grandTotalValue, [], [])"
>
{{ getAggregator([], []).format(grandTotalValue) }}
</td>
</tr>
</template>

<script setup>
import { computed } from 'vue'
import { useProvidePivotData } from '@/composables/useProvidePivotData'

const props = defineProps({
colTotal: {
type: Boolean,
required: true
},
rowTotal: {
type: Boolean,
required: true
},
localeStrings: {
type: Object,
required: true
},
tableOptions: {
type: Object,
required: true
}
})

const {
getAggregator,
rowTotalColors,
colAttrs,
rowAttrs,
colKeys,
pivotData
} = useProvidePivotData()

const grandTotalValue = computed(() => {
return getAggregator([], []).value()
})

const getColTotalStyle = (colKey) => {
const value = getAggregator([], colKey).value()
return rowTotalColors(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>
Loading