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

Allow Multiple Reduction Functions #7

Closed
wants to merge 10 commits into from
223 changes: 113 additions & 110 deletions demo/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,134 +2,137 @@
<div id="app" class="container mt-5">
<h1 class="border-bottom pb-2 mb-4">Vue pivot table demo</h1>

<h2 class="border-bottom pb-2 mb-4">Pivot <small>(drag & drop UI + PivotTable)</small></h2>
<h2 class="border-bottom pb-2 mb-4">Pivot
<small>(drag & drop UI + PivotTable)</small>
</h2>

<div class="mb-5">
<pivot
:data="data"
:fields="fields"
:row-fields="rowFields"
:col-fields="colFields"
:reducer="reducer"
:default-show-settings="defaultShowSettings"
>
<template slot="value" slot-scope="{ value }">
{{ value | number }}
</template>
<template slot="genderHeader" slot-scope="{ value }">
<svg v-if="value == 'female'" aria-hidden="true" data-prefix="fas" data-icon="venus" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 288 512" class="svg-inline--fa fa-venus fa-fw"><path fill="currentColor" d="M288 176c0-79.5-64.5-144-144-144S0 96.5 0 176c0 68.5 47.9 125.9 112 140.4V368H76c-6.6 0-12 5.4-12 12v40c0 6.6 5.4 12 12 12h36v36c0 6.6 5.4 12 12 12h40c6.6 0 12-5.4 12-12v-36h36c6.6 0 12-5.4 12-12v-40c0-6.6-5.4-12-12-12h-36v-51.6c64.1-14.5 112-71.9 112-140.4zm-224 0c0-44.1 35.9-80 80-80s80 35.9 80 80-35.9 80-80 80-80-35.9-80-80z" class=""></path></svg>
<svg v-else-if="value == 'male'" aria-hidden="true" data-prefix="fas" data-icon="mars" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512" class="svg-inline--fa fa-mars fa-fw"><path fill="currentColor" d="M372 64h-79c-10.7 0-16 12.9-8.5 20.5l16.9 16.9-80.7 80.7c-22.2-14-48.5-22.1-76.7-22.1C64.5 160 0 224.5 0 304s64.5 144 144 144 144-64.5 144-144c0-28.2-8.1-54.5-22.1-76.7l80.7-80.7 16.9 16.9c7.6 7.6 20.5 2.2 20.5-8.5V76c0-6.6-5.4-12-12-12zM144 384c-44.1 0-80-35.9-80-80s35.9-80 80-80 80 35.9 80 80-35.9 80-80 80z" class=""></path></svg>
{{ value | capitalize }}
</template>
</pivot>
</div>
<button @click="changeData">Change Data</button>

<h2 class="border-bottom pb-2 mb-4">PivotTable <small>(standalone)</small></h2>

<div class="mb-5">
<pivot-table
:data="asyncData"
:row-fields="rowFields"
:col-fields="colFields"
:reducer="reducer"
:default-show-settings="defaultShowSettings"
:is-data-loading="isDataLoading"
<pivot :data="data"
:fields="fields"
:row-fields="rowFields"
:value-fields="valueFields"
:col-fields="colFields"
:default-show-settings="defaultShowSettings"
:hide-empty="hideEmpty"
>
<template slot="value" slot-scope="{ value }">
{{ value | number }}
</template>
<template slot="genderHeader" slot-scope="{ value }">
<svg v-if="value == 'female'" aria-hidden="true" data-prefix="fas" data-icon="venus" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 288 512" class="svg-inline--fa fa-venus fa-fw"><path fill="currentColor" d="M288 176c0-79.5-64.5-144-144-144S0 96.5 0 176c0 68.5 47.9 125.9 112 140.4V368H76c-6.6 0-12 5.4-12 12v40c0 6.6 5.4 12 12 12h36v36c0 6.6 5.4 12 12 12h40c6.6 0 12-5.4 12-12v-36h36c6.6 0 12-5.4 12-12v-40c0-6.6-5.4-12-12-12h-36v-51.6c64.1-14.5 112-71.9 112-140.4zm-224 0c0-44.1 35.9-80 80-80s80 35.9 80 80-35.9 80-80 80-80-35.9-80-80z" class=""></path></svg>
<svg v-else-if="value == 'male'" aria-hidden="true" data-prefix="fas" data-icon="mars" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512" class="svg-inline--fa fa-mars fa-fw"><path fill="currentColor" d="M372 64h-79c-10.7 0-16 12.9-8.5 20.5l16.9 16.9-80.7 80.7c-22.2-14-48.5-22.1-76.7-22.1C64.5 160 0 224.5 0 304s64.5 144 144 144 144-64.5 144-144c0-28.2-8.1-54.5-22.1-76.7l80.7-80.7 16.9 16.9c7.6 7.6 20.5 2.2 20.5-8.5V76c0-6.6-5.4-12-12-12zM144 384c-44.1 0-80-35.9-80-80s35.9-80 80-80 80 35.9 80 80-35.9 80-80 80z" class=""></path></svg>
{{ value | capitalize }}
</template>
<template slot="loading">
<div class="text-center">
<svg aria-hidden="true" data-prefix="fas" data-icon="spinner" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" class="svg-inline--fa fa-spinner fa-fw fa-pulse"><path fill="currentColor" d="M304 48c0 26.51-21.49 48-48 48s-48-21.49-48-48 21.49-48 48-48 48 21.49 48 48zm-48 368c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48-21.49-48-48-48zm208-208c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48-21.49-48-48-48zM96 256c0-26.51-21.49-48-48-48S0 229.49 0 256s21.49 48 48 48 48-21.49 48-48zm12.922 99.078c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48c0-26.509-21.491-48-48-48zm294.156 0c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48c0-26.509-21.49-48-48-48zM108.922 60.922c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48-21.491-48-48-48z" class=""></path></svg>
Loading...
</div>
</template>
</pivot-table>
</pivot>
</div>
</div>
</template>

<script>
import Pivot from '../src/Pivot'
import PivotTable from '../src/PivotTable'
import data from './data'
import Pivot from '../src/Pivot'
import PivotTable from '../src/PivotTable'
import data from './data'

export default {
name: 'app',
components: { Pivot, PivotTable },
data: () => {
return {
data: data,
asyncData: [],
fields: [],
rowFields: [{
getter: item => item.country,
label: 'Country'
}, {
getter: item => item.gender,
label: 'Gender',
headerSlotName: 'genderHeader'
}],
colFields: [{
getter: item => item.year,
label: 'Year'
}],
reducer: (sum, item) => sum + item.count,
defaultShowSettings: true,
isDataLoading: false
}
},
created: function() {
this.isDataLoading = true
setTimeout(() => {
this.asyncData = data
this.isDataLoading = false
}, 3000)
},
filters: {
number: function(value) {
return value.toLocaleString()
export default {
name: 'app',
components: {Pivot, PivotTable},
data: () => {
return {
data: [],
fields: [],
rowFields: [],
colFields: [],
valueFields: [],
defaultShowSettings: true,
hideEmpty: true,
}
},
capitalize: function(value) {
return value.replace(/\b\w/g, l => l.toUpperCase())
}
},
}
methods: {
changeData() {
this.data = data,
this.fields = [{
getter: item => item.level0,
label: 'Level0',
}, {
getter: item => item.level1,
label: 'Level1',
}, {
getter: item => item.level2,
label: 'Level2',
}, {
getter: item => item.level3,
label: 'Level3',
}, {
getter: item => item.address,
label: 'Address'
}, {
getter: item => item.rto,
label: 'RTO'
}, {
getter: item => item.rpo,
label: 'RPO'
}];
this.rowFields = [{
getter: item => item.application,
label: 'Application'
}];
this.colFields = [];
this.valueFields = [
{
label: 'RTO',
getter: item => item.rto,
type: 'min',
title: 'Min'
},
{
label: 'RPO',
getter: item => item.rpo,
type: 'min',
title: 'Min'
}
];
}
},
created: function () {
this.isDataLoading = true
setTimeout(() => {
this.asyncData = data
this.isDataLoading = false
}, 3000)
},
filters: {
number: function (value) {
return value.toLocaleString()
},
capitalize: function (value) {
return value.replace(/\b\w/g, l => l.toUpperCase())
}
},
}
</script>

<style lang="scss">
$enable-rounded: false;
@import '~bootstrap/scss/bootstrap.scss';
$enable-rounded: false;
@import '~bootstrap/scss/bootstrap.scss';

/* FontAwesome icons */
.svg-inline--fa.fa-fw {
width: 1.25em;
}

.svg-inline--fa {
display: inline-block;
font-size: inherit;
height: 1em;
overflow: visible;
vertical-align: -.125em !important;
}
/* FontAwesome icons */
.svg-inline--fa.fa-fw {
width: 1.25em;
}

.fa-pulse {
animation: fa-spin 1s infinite steps(8);
}
.svg-inline--fa {
display: inline-block;
font-size: inherit;
height: 1em;
overflow: visible;
vertical-align: -.125em !important;
}

@keyframes fa-spin {
0% {
transform: rotate(0deg);
.fa-pulse {
animation: fa-spin 1s infinite steps(8);
}

to {
transform: rotate(1turn);
@keyframes fa-spin {
0% {
transform: rotate(0deg);
}

to {
transform: rotate(1turn);
}
}
}
</style>
53 changes: 16 additions & 37 deletions demo/data.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading