5050 </div >
5151
5252 <!-- Table -->
53- <div class =" col table-responsive pivottable" >
53+ <div class =" p-0 position-relative col table-responsive pivottable" >
5454 <pivot-table
5555 ref =" pivottable"
5656 :data =" data"
7070 <slot name =" loading" ></slot >
7171 </template >
7272 </pivot-table >
73+ <transition name =" copied-alert" >
74+ <div v-if =" showCopiedAlert" class =" alert alert-secondary pivot-copied-alert" >
75+ Copied to clipboard
76+ </div >
77+ </transition >
7378 </div >
7479
7580 <div v-if =" showSettings" class =" table-option-button circle-background bg-primary dropdown-toggle" data-toggle =" dropdown" aria-haspopup =" true" aria-expanded =" false" v-b-tooltip:hover title =" Show menu" ></div >
7681 <div class =" dropdown-menu" aria-labelledby =" dropdownMenuButton" >
77- <a class =" dropdown-item" href =" #!" @click =" _clickedSaveButton('csv')" >Save table in CSV</a >
78- <a class =" dropdown-item" href =" #!" @click =" _clickedSaveButton('tsv')" >Save table in TSV</a >
82+ <button ref =" pivot-copy-button" class =" dropdown-item" >Copy table to clipboard</button >
83+ <button class =" dropdown-item" @click =" _clickedSaveButton('csv')" >Save table in CSV</button >
84+ <button class =" dropdown-item" @click =" _clickedSaveButton('tsv')" >Save table in TSV</button >
7985 </div >
8086 </div >
8187 </div >
8288</template >
8389
8490<script >
91+ import Clipboard from ' clipboard'
8592import PivotTable from ' ./PivotTable.vue'
8693import naturalSort from ' javascript-natural-sort'
8794import Draggable from ' vuedraggable'
@@ -161,12 +168,23 @@ export default {
161168 colFields: this .fields .colFields ,
162169 fieldsOrder: this .fields .fieldsOrder
163170 },
164- dragging: false
171+ dragging: false ,
172+ showCopiedAlert: false
165173 }
166174 },
167175 created () {
168176 this ._sortFields (this .internal .fieldsOrder )
169177 },
178+ mounted () {
179+ const self = this
180+ const clipboard = new Clipboard (self .$refs [' pivot-copy-button' ], {
181+ target : () => self .$refs .pivottable .$el
182+ })
183+ clipboard .on (' success' , (e ) => {
184+ e .clearSelection ()
185+ self .onPivotTableCopied (e)
186+ })
187+ },
170188 computed: {
171189 dragAreaClass : function () {
172190 return this .dragging ? ' drag-area--highlight' : null
@@ -239,6 +257,10 @@ export default {
239257 this .internal .fieldsOrder = { ... this .internal .fieldsOrder , [label]: ' desc' }
240258 }
241259 this ._sortFields (this .internal .fieldsOrder )
260+ },
261+ onPivotTableCopied () {
262+ this .showCopiedAlert = true
263+ setTimeout (() => { this .showCopiedAlert = false }, 700 )
242264 }
243265 }
244266}
@@ -360,6 +382,7 @@ $carret-bold-svg: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/200
360382}
361383
362384.pivottable {
385+ margin : 0 15px ;
363386 & ~ .table-option-button {
364387 opacity : 0 ;
365388 }
@@ -381,4 +404,18 @@ $hamburger-svg: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/
381404 border-width : 2px !important ;
382405 left : $base-space * 3 + 10rem - $border-space * 3 ;
383406}
407+
408+ .pivot-copied-alert {
409+ position : absolute ;
410+ bottom : 1rem ;
411+ right : 1rem ;
412+ }
413+
414+ .copied-alert-enter-active {
415+ opacity : 0.6 ;
416+ }
417+ .copied-alert-leave-active {
418+ opacity : 0 ;
419+ transition : all 0.7s ease ;
420+ }
384421 </style >
0 commit comments