Skip to content

Commit f049a6d

Browse files
committed
vue
1 parent 6652c88 commit f049a6d

File tree

5 files changed

+5302
-4686
lines changed

5 files changed

+5302
-4686
lines changed

Vue/src/assets/main.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
-webkit-font-smoothing: antialiased;
44
-moz-osx-font-smoothing: grayscale;
55
color: #2c3e50;
6-
margin: 50px 50px;
7-
width: 90vh;
6+
margin: 50px;
7+
width: 90vw;
88
}

Vue/src/components/HomeContent.vue

Lines changed: 149 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,158 @@
1-
<script setup lang="ts">
2-
import { computed, ref } from 'vue';
3-
1+
<script setup lang='ts'>
2+
import { ref } from 'vue';
43
import 'devextreme/dist/css/dx.material.blue.light.compact.css';
5-
import DxButton from 'devextreme-vue/button';
4+
import DxPivotGrid, { DxFieldChooser } from 'devextreme-vue/pivot-grid';
5+
import DxCheckBox, { type DxCheckBoxTypes } from 'devextreme-vue/check-box';
6+
import PivotGridDataSource from 'devextreme/ui/pivot_grid/data_source';
7+
import service, { type Sale } from './data';
8+
9+
const isConditional = ref(true);
10+
const pivotGridRef = ref<DxPivotGrid|null>(null);
11+
12+
function toggleConditionalChanged(e: DxCheckBoxTypes.ValueChangedEvent) {
13+
isConditional.value = e.value;
14+
pivotGridRef.value?.instance?.getDataSource().reload();
15+
}
16+
17+
interface CustomSummaryValue {
18+
summaryProcess?: string;
19+
value?: any;
20+
totalValue?: any;
21+
}
22+
23+
const tempSales = service.getSales();
624
7-
const props = defineProps({
8-
text: {
9-
type: String,
10-
default: 'count',
11-
},
25+
tempSales.forEach((sale: Sale, index: number) => {
26+
sale.isApproved = index % 2 !== 0;
1227
});
13-
const count = ref(0);
14-
const buttonText = computed<string>(
15-
() => `Click ${props.text}: ${count.value}`
16-
);
17-
function clickHandler() {
18-
count.value += 1;
28+
29+
const sales = tempSales;
30+
31+
function calculateCustomSummary(options: CustomSummaryValue) {
32+
switch (options.summaryProcess) {
33+
case 'start':
34+
options.totalValue = { conditionalVal: 0, rawVal: 0, count: 0 };
35+
break;
36+
case 'calculate':
37+
options.totalValue.count += 1;
38+
options.totalValue.rawVal += options.value.amount;
39+
if (options.value.isApproved) {
40+
options.totalValue.conditionalVal += options.value.amount;
41+
}
42+
break;
43+
case 'finalize':
44+
if (options.totalValue.count === 1 || !isConditional.value) {
45+
options.totalValue = options.totalValue.rawVal;
46+
} else {
47+
options.totalValue = options.totalValue.conditionalVal;
48+
}
49+
break;
50+
default: break;
51+
}
1952
}
53+
54+
const dataSource: PivotGridDataSource = new PivotGridDataSource({
55+
fields: [{
56+
caption: 'Region',
57+
width: 120,
58+
dataField: 'region',
59+
area: 'row',
60+
expanded: true,
61+
}, {
62+
caption: 'City',
63+
dataField: 'city',
64+
width: 150,
65+
area: 'row',
66+
selector: (data: Sale): string => `${data.city} (${data.country})`,
67+
}, {
68+
dataField: 'date',
69+
dataType: 'date',
70+
area: 'column',
71+
expanded: true,
72+
}, {
73+
caption: 'Sales',
74+
dataType: 'number',
75+
summaryType: 'custom',
76+
format: 'currency',
77+
area: 'data',
78+
calculateCustomSummary,
79+
}, {
80+
caption: 'Approved',
81+
dataField: 'isApproved',
82+
summaryType: 'sum',
83+
area: 'data',
84+
}],
85+
store: sales,
86+
});
87+
2088
</script>
2189
<template>
2290
<div>
23-
<DxButton
24-
:text="buttonText"
25-
@click="clickHandler"
26-
/>
91+
<div class='long-title'>
92+
<h3>Conditional Summary Calculation</h3>
93+
</div>
94+
<DxPivotGrid
95+
ref='pivotGridRef'
96+
:allow-sorting-by-summary='true'
97+
:allow-sorting='true'
98+
:allow-filtering='true'
99+
:allow-expand-all='true'
100+
:height='440'
101+
:show-borders='true'
102+
:data-source='dataSource'
103+
>
104+
<DxFieldChooser :enabled='false'/>
105+
</DxPivotGrid>
106+
<div class='options'>
107+
<div class='caption'>Options</div>
108+
<div class='option'>
109+
<DxCheckBox
110+
:value.sync='isConditional'
111+
text='Toggle Conditional Summary Calculation'
112+
@value-changed='toggleConditionalChanged'
113+
/>
114+
</div>
115+
</div>
27116
</div>
28117
</template>
118+
<style scoped>
119+
#sales {
120+
margin-top: 80px;
121+
}
122+
123+
.long-title h3 {
124+
font-family: 'Segoe UI Light', 'Helvetica Neue Light', 'Segoe UI',
125+
'Helvetica Neue', 'Trebuchet MS', Verdana;
126+
font-weight: 200;
127+
font-size: 28px;
128+
text-align: center;
129+
margin-bottom: 20px;
130+
}
131+
132+
.options {
133+
margin-top: 20px;
134+
padding: 20px;
135+
background: #f5f5f5;
136+
}
137+
138+
.options .caption {
139+
font-size: 18px;
140+
font-weight: 500;
141+
}
142+
143+
.option {
144+
margin-top: 10px;
145+
}
146+
147+
.option > span {
148+
width: 120px;
149+
display: inline-block;
150+
}
151+
152+
.option > .dx-widget {
153+
display: inline-block;
154+
vertical-align: middle;
155+
width: 100%;
156+
max-width: 350px;
157+
}
158+
</style>

0 commit comments

Comments
 (0)