Skip to content
This repository was archived by the owner on Mar 9, 2023. It is now read-only.

Commit 3170d32

Browse files
committed
Config clipboard in mounted, don't use unique id
1 parent 8f40360 commit 3170d32

File tree

1 file changed

+13
-33
lines changed

1 file changed

+13
-33
lines changed

src/Pivot.vue

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
<!-- Table -->
5353
<div class="p-0 position-relative col table-responsive pivottable">
5454
<pivot-table
55-
:id="`pivottable-${uniqueId}`"
5655
ref="pivottable"
5756
:data="data"
5857
:row-fields="internal.rowFields"
@@ -78,15 +77,7 @@
7877

7978
<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>
8079
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
81-
<a
82-
v-clipboard
83-
v-clipboard:success="onPivotTableCopied"
84-
:data-clipboard-target="`#pivottable-${uniqueId}`"
85-
class="dropdown-item"
86-
href="#"
87-
>
88-
Copy table to clipboard
89-
</a>
80+
<a ref="pivot-copy-button" class="dropdown-item" href="#">Copy table to clipboard</a>
9081
<a class="dropdown-item" href="#!" @click="_clickedSaveButton('csv')">Save table in CSV</a>
9182
<a class="dropdown-item" href="#!" @click="_clickedSaveButton('tsv')">Save table in TSV</a>
9283
</div>
@@ -104,25 +95,7 @@ import { VBTooltip } from 'bootstrap-vue'
10495
export default {
10596
name: 'Pivot',
10697
components: { PivotTable, Draggable },
107-
directives: {
108-
'b-tooltip': VBTooltip,
109-
clipboard: {
110-
bind (el, binding) {
111-
if (binding.arg === 'success') {
112-
el._clipboard_success = binding.value
113-
} else if (binding.arg === 'error') {
114-
el._clipboard_error = binding.value
115-
} else {
116-
const clipboard = new Clipboard(el)
117-
clipboard.on('success', (e) => {
118-
e.clearSelection()
119-
const callback = el._clipboard_success
120-
callback && callback(e)
121-
})
122-
}
123-
}
124-
}
125-
},
98+
directives: { 'b-tooltip': VBTooltip },
12699
model: {
127100
prop: 'fields',
128101
event: 'change'
@@ -193,14 +166,21 @@ export default {
193166
colFields: this.fields.colFields,
194167
fieldsOrder: this.fields.fieldsOrder
195168
},
196-
dragging: false,
197-
uniqueId: ''
169+
dragging: false
198170
}
199171
},
200172
created () {
201173
this._sortFields(this.internal.fieldsOrder)
202-
// randomly selected string
203-
this.uniqueId = Math.random().toString(36).substring(7)
174+
},
175+
mounted () {
176+
const self = this
177+
const clipboard = new Clipboard(self.$refs['pivot-copy-button'], {
178+
target: () => self.$refs.pivottable.$el
179+
})
180+
clipboard.on('success', (e) => {
181+
e.clearSelection()
182+
self.onPivotTableCopied(e)
183+
})
204184
},
205185
computed: {
206186
dragAreaClass: function () {

0 commit comments

Comments
 (0)