Skip to content
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

feat: Adds options to show subtotals in Pivot Table #24960

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ export default function PivotTableChart(props: PivotTableProps) {
rowSubtotalPosition,
colSubtotalPosition,
colTotals,
colSubTotals,
rowTotals,
rowSubTotals,
valueFormat,
currencyFormat,
emitCrossFilters,
Expand Down Expand Up @@ -432,7 +434,9 @@ export default function PivotTableChart(props: PivotTableProps) {
clickRowHeaderCallback: toggleFilter,
clickColumnHeaderCallback: toggleFilter,
colTotals,
colSubTotals,
rowTotals,
rowSubTotals,
highlightHeaderCellsOnHover:
emitCrossFilters ||
isFeatureEnabled(FeatureFlag.DRILL_BY) ||
Expand All @@ -444,10 +448,12 @@ export default function PivotTableChart(props: PivotTableProps) {
}),
[
colTotals,
colSubTotals,
dateFormatters,
emitCrossFilters,
metricColorFormatters,
rowTotals,
rowSubTotals,
selectedFilters,
toggleFilter,
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,18 @@ const config: ControlPanelConfig = {
},
},
],
[
{
name: 'rowSubTotals',
config: {
type: 'CheckboxControl',
label: t('Show rows subtotal'),
default: false,
renderTrigger: true,
description: t('Display row level subtotal'),
},
},
],
[
{
name: 'colTotals',
Expand All @@ -230,6 +242,18 @@ const config: ControlPanelConfig = {
},
},
],
[
{
name: 'colSubTotals',
config: {
type: 'CheckboxControl',
label: t('Show columns subtotal'),
default: false,
renderTrigger: true,
description: t('Display column level subtotal'),
},
},
],
[
{
name: 'transposePivot',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ export default function transformProps(chartProps: ChartProps<QueryFormData>) {
rowSubtotalPosition,
colSubtotalPosition,
colTotals,
colSubTotals,
rowTotals,
rowSubTotals,
valueFormat,
dateFormat,
metricsLayout,
Expand Down Expand Up @@ -156,7 +158,9 @@ export default function transformProps(chartProps: ChartProps<QueryFormData>) {
rowSubtotalPosition,
colSubtotalPosition,
colTotals,
colSubTotals,
rowTotals,
rowSubTotals,
valueFormat,
currencyFormat,
emitCrossFilters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ export class TableRenderer extends React.Component {

const colSubtotalDisplay = {
displayOnTop: false,
enabled: rowTotals,
enabled: tableOptions.colSubTotals,
hideOnExpand: false,
...subtotalOptions.colSubtotalDisplay,
};

const rowSubtotalDisplay = {
displayOnTop: false,
enabled: colTotals,
enabled: tableOptions.rowSubTotals,
hideOnExpand: false,
...subtotalOptions.rowSubtotalDisplay,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ interface PivotTableCustomizeProps {
rowSubtotalPosition: boolean;
colSubtotalPosition: boolean;
colTotals: boolean;
colSubTotals: boolean;
rowTotals: boolean;
rowSubTotals: boolean;
valueFormat: string;
currencyFormat: Currency;
setDataMask: SetDataMaskHook;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ const formData: PivotTableQueryFormData = {
rowSubtotalPosition: true,
colSubtotalPosition: true,
colTotals: true,
colSubTotals: true,
rowTotals: true,
rowSubTotals: true,
valueFormat: 'SMART_NUMBER',
datasource: '5__table',
viz_type: 'my_chart',
Expand Down
1 change: 1 addition & 0 deletions superset/migrations/shared/migrate_viz/processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class MigratePivotTable(MigrateViz):
def _pre_action(self) -> None:
if pivot_margins := self.data.get("pivot_margins"):
self.data["colTotals"] = pivot_margins
self.data["colSubTotals"] = pivot_margins

if pandas_aggfunc := self.data.get("pandas_aggfunc"):
self.data["pandas_aggfunc"] = self.aggregation_mapping[pandas_aggfunc]
Expand Down
1 change: 1 addition & 0 deletions tests/unit_tests/migrations/viz/pivot_table_v1_v2_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"any_other_key": "untouched",
"aggregateFunction": "Sum",
"colTotals": True,
"colSubTotals": True,
"combineMetric": True,
"form_data_bak": SOURCE_FORM_DATA,
"granularity_sqla": "ds",
Expand Down