|
| 1 | +<script> |
| 2 | + import { PivotViewComponent, GroupingBar, Toolbar, ConditionalFormatting } from "@syncfusion/ej2-vue-pivotview"; |
| 3 | + import { createApp } from 'vue'; |
| 4 | + const app = createApp(); |
| 5 | + var templateVue = app.component("cellTemplate",{ |
| 6 | + data() |
| 7 | + { |
| 8 | + return{ |
| 9 | + data:{} |
| 10 | + }; |
| 11 | + }, |
| 12 | + methods:{ |
| 13 | + getCellContent: function(e){ |
| 14 | + var template; |
| 15 | + if(e && e.cellInfo && e.cellInfo.axis == 'value'){ |
| 16 | + if(e.cellInfo.actualValue < 1000) |
| 17 | + { |
| 18 | + template = '<div class="icon-loss"></div>' |
| 19 | + } |
| 20 | + else if (e.cellInfo.actualValue > 1000 && e.cellInfo.actualValue < 5000) { |
| 21 | + template = '<div class=" icon-neutral "></div>'; |
| 22 | + } else if (e.cellInfo.actualValue > 5000) { |
| 23 | + template = '<div class="icon-profit"></div>'; |
| 24 | + } |
| 25 | + else{ |
| 26 | + template='' |
| 27 | + } |
| 28 | + } |
| 29 | + else{ |
| 30 | + template='' |
| 31 | + } |
| 32 | + return template; |
| 33 | + } |
| 34 | + }, |
| 35 | + template: `<div v-if="getCellContent(data) !== ''"> |
| 36 | + <div v-html="getCellContent(data)"></div> |
| 37 | + </div>`, |
| 38 | + }); |
| 39 | + |
| 40 | +export default{ |
| 41 | + components: { |
| 42 | + "ejs-pivotview": PivotViewComponent |
| 43 | + }, |
| 44 | + data() |
| 45 | + { |
| 46 | + return{ |
| 47 | + dataSourceSettings:{ |
| 48 | + dataSource:[ |
| 49 | + { Amount: 5100, Country: "Canada", Date: "FY 2006", Quarter: "Q1", Product: "Car", Quantity: 21, State: "Alberta" }, |
| 50 | + { Amount: 1900, Country: "France", Date: "FY 2007", Quarter: "Q2", Product: "Bike", Quantity: 23, State: "Alberta" }, |
| 51 | + { Amount: 1000, Country: "Sweden", Date: "FY 2008", Quarter: "Q3", Product: "Car", Quantity: 29, State: "Alberta" }, |
| 52 | + { Amount: 2060, Country: "Canada", Date: "FY 2006", Quarter: "Q4", Product: "Bike", Quantity: 93, State: "British Columbia" }, |
| 53 | + { Amount: 6200, Country: "France", Date: "FY 2007", Quarter: "Q1", Product: "Car", Quantity: 36, State: "British Columbia" }, |
| 54 | + { Amount: 2000, Country: "Sweden", Date: "FY 2008", Quarter: "Q2", Product: "Bike", Quantity: 31, State: "British Columbia" }, |
| 55 | + { Amount: 1300, Country: "Canada", Date: "FY 2005", Quarter: "Q3", Product: "Car", Quantity: 45, State: "Brunswick" }, |
| 56 | + { Amount: 3400, Country: "France", Date: "FY 2006", Quarter: "Q4", Product: "Bike", Quantity: 47, State: "Brunswick" }, |
| 57 | + { Amount: 2300, Country: "Sweden", Date: "FY 2007", Quarter: "Q1", Product: "Car", Quantity: 43, State: "Brunswick" }, |
| 58 | + { Amount: 5100, Country: "Canada", Date: "FY 2006", Quarter: "Q2", Product: "Bike", Quantity: 21, State: "Alberta" }, |
| 59 | + { Amount: 1900, Country: "France", Date: "FY 2007", Quarter: "Q3", Product: "Car", Quantity: 23, State: "Alberta" }, |
| 60 | + { Amount: 1000, Country: "Sweden", Date: "FY 2008", Quarter: "Q4", Product: "Bike", Quantity: 29, State: "Alberta" }, |
| 61 | + { Amount: 2060, Country: "Canada", Date: "FY 2006", Quarter: "Q1", Product: "Car", Quantity: 93, State: "British Columbia" }, |
| 62 | + { Amount: 6200, Country: "France", Date: "FY 2007", Quarter: "Q2", Product: "Bike", Quantity: 36, State: "British Columbia" }, |
| 63 | + { Amount: 2000, Country: "Sweden", Date: "FY 2008", Quarter: "Q3", Product: "Car", Quantity: 31, State: "British Columbia" }, |
| 64 | + { Amount: 1300, Country: "Canada", Date: "FY 2005", Quarter: "Q4", Product: "Bike", Quantity: 45, State: "Brunswick" }, |
| 65 | + { Amount: 3400, Country: "France", Date: "FY 2006", Quarter: "Q1", Product: "Car", Quantity: 47, State: "Brunswick" }, |
| 66 | + { Amount: 2300, Country: "Sweden", Date: "FY 2007", Quarter: "Q2", Product: "Bike", Quantity: 43, State: "Brunswick" }, |
| 67 | + ], |
| 68 | + rows: [{name:'Country'},{name: 'Product'}], |
| 69 | + columns: [{name:'Date'}], |
| 70 | + values: [{name:'Amount'}, {name:'Quantity', caption:'Units Sold'}], |
| 71 | + formatSettings: [{name:'Amount', format:'C1'}], |
| 72 | + conditionalFormatSettings:[ |
| 73 | + { |
| 74 | + |
| 75 | + value1:3000, |
| 76 | + conditions:'LessThan', |
| 77 | + style:{ |
| 78 | + backgroundColor: '#80cbc4', |
| 79 | + color: 'black', |
| 80 | + fontFamily: 'Tahoma', |
| 81 | + fontSize: '12px' |
| 82 | + } |
| 83 | + } |
| 84 | + ] |
| 85 | + }, |
| 86 | + height:'350px', |
| 87 | + width:'900px', |
| 88 | + showGroupingBar: true, |
| 89 | + showToolbar: true, |
| 90 | + allowConditionalFormatting: true, |
| 91 | + toolbar: ["ConditionalFormatting"], |
| 92 | + cellTemplate: function() |
| 93 | + { |
| 94 | + return{ |
| 95 | + template: templateVue |
| 96 | + }; |
| 97 | + } |
| 98 | + }}, |
| 99 | + provide: |
| 100 | + { |
| 101 | + pivotview:[ GroupingBar, Toolbar, ConditionalFormatting ] |
| 102 | + } |
| 103 | +} |
| 104 | +</script> |
| 105 | +<template> |
| 106 | + <ejs-pivotview :height="height" :width="width" |
| 107 | + :dataSourceSettings="dataSourceSettings" |
| 108 | + :showGroupingBar ="showGroupingBar" |
| 109 | + :cellTemplate="cellTemplate" |
| 110 | + :showToolbar="showToolbar" |
| 111 | + :allowConditionalFormatting="allowConditionalFormatting" |
| 112 | + :toolbar="toolbar" |
| 113 | + ></ejs-pivotview> |
| 114 | +</template> |
| 115 | + |
| 116 | +<style > |
| 117 | + @import "../node_modules/@syncfusion/ej2-base/styles/bootstrap5.css"; |
| 118 | + @import "../node_modules/@syncfusion/ej2-inputs/styles/bootstrap5.css"; |
| 119 | + @import "../node_modules/@syncfusion/ej2-buttons/styles/bootstrap5.css"; |
| 120 | + @import "../node_modules/@syncfusion/ej2-splitbuttons/styles/bootstrap5.css"; |
| 121 | + @import "../node_modules/@syncfusion/ej2-calendars/styles/bootstrap5.css"; |
| 122 | + @import "../node_modules/@syncfusion/ej2-dropdowns/styles/bootstrap5.css"; |
| 123 | + @import "../node_modules/@syncfusion/ej2-lists/styles/bootstrap5.css"; |
| 124 | + @import "../node_modules/@syncfusion/ej2-popups/styles/bootstrap5.css"; |
| 125 | + @import "../node_modules/@syncfusion/ej2-navigations/styles/bootstrap5.css"; |
| 126 | + @import "../node_modules/@syncfusion/ej2-grids/styles/bootstrap5.css"; |
| 127 | + @import "../node_modules/@syncfusion/ej2-vue-pivotview/styles/bootstrap5.css"; |
| 128 | + .icon-neutral { |
| 129 | + display: inline-block !important; |
| 130 | + width: 0; |
| 131 | + height: 0; |
| 132 | + border-top: 5px solid transparent; |
| 133 | + border-bottom: 5px solid transparent; |
| 134 | + border-left: 5px solid blue; |
| 135 | + margin-left: 10px; |
| 136 | + } |
| 137 | + .icon-loss { |
| 138 | + display: inline-block !important; |
| 139 | + width: 0; |
| 140 | + height: 0; |
| 141 | + border-left: 5px solid transparent; |
| 142 | + border-right: 5px solid transparent; |
| 143 | + border-top: 5px solid #f00; |
| 144 | + margin-left: 10px; |
| 145 | + } |
| 146 | + .icon-profit { |
| 147 | + display: inline-block !important; |
| 148 | + width: 0; |
| 149 | + height: 0; |
| 150 | + border-left: 5px solid transparent; |
| 151 | + border-right: 5px solid transparent; |
| 152 | + border-bottom: 5px solid darkgreen; |
| 153 | + margin-left: 10px; |
| 154 | + } |
| 155 | + </style> |
| 156 | + |
| 157 | + |
0 commit comments