Skip to content

Commit 1334bef

Browse files
committed
generating custom action buttons based on initial config and emit events
1 parent 706a0fe commit 1334bef

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

src/App.vue

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div id="app">
3-
<vue-bootstrap4-table :rows="rows" :columns="columns" :config="config" @on-select-rows="onSelectRows" @refresh-data="onRefreshData">
3+
<vue-bootstrap4-table :rows="rows" :columns="columns" :config="config" :actions="actions" @on-select-rows="onSelectRows" @refresh-data="onRefreshData" @on-test="testone">
44
<template slot="pagination-info" slot-scope="props">
55
This page total is {{props.currentPageRowsLength}} |
66
Filterd results total is {{props.filteredRowsLength}} |
@@ -90,13 +90,33 @@
9090
per_page_options: [1, 15, 20, 30],
9191
show_reset_button: true,
9292
show_refresh_button: true,
93-
}
93+
},
94+
msg : "msg from parent",
95+
actions: [
96+
{
97+
btn_text: "test",
98+
event_name: "on-test",
99+
event_payload: {
100+
msg: "my custom msg"
101+
}
102+
},
103+
{
104+
btn_text: "test2",
105+
event_name: "on-test-two"
106+
},
107+
{
108+
btn_text: "test3",
109+
event_name: "on-test-three"
110+
}
111+
],
94112
}
95113
},
96114
methods: {
97115
onSelectRows(payload) {
98116
console.log(payload);
99-
117+
},
118+
testone(payload) {
119+
console.log(payload);
100120
},
101121
onRefreshData() {
102122
let dummy = [{

src/components/VueBootstrap4Table.vue

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<tr>
1313
<th :colspan="headerColSpan">
1414
<div class="row" v-if="global_search.visibility">
15+
<!-- global search text starts here -->
1516
<div class="input-group col-md-2">
1617
<input ref="global_search" type="text" class="form-control" :placeholder="global_search.placeholder" @keyup.stop="updateGlobalSearch($event)">
1718
<div class="input-group-append vbt-global-search-clear" @click="clearGlobalSearch">
@@ -22,6 +23,9 @@
2223
</span>
2324
</div>
2425
</div>
26+
<!-- global search text ends here -->
27+
28+
<!-- refresh & reset button starts here -->
2529
<div class="btn-group col-md-1" role="group" aria-label="Basic example">
2630
<button v-if="show_refresh_button" type="button" class="btn btn-secondary" @click="$emit('refresh-data')">
2731
<slot name="refresh-button-text">
@@ -34,6 +38,16 @@
3438
</slot>
3539
</button>
3640
</div>
41+
<!-- refresh & reset button ends here -->
42+
43+
<!-- action buttons starts here -->
44+
<div class="btn-group col-md-9 justify-content-end" role="group" aria-label="Basic example">
45+
<button v-for="(action, key, index) in actions" :key="index" type="button" class="btn btn-secondary" @click="$emit(action.event_name,action.event_payload)">
46+
{{action.btn_text}}
47+
</button>
48+
</div>
49+
<!-- action buttons button ends here -->
50+
3751
</div>
3852
</th>
3953
</tr>
@@ -213,7 +227,13 @@ export default {
213227
default: function () {
214228
return {};
215229
}
216-
}
230+
},
231+
actions: {
232+
type: Array,
233+
default: function () {
234+
return [];
235+
}
236+
},
217237
},
218238
data: function () {
219239
return {

0 commit comments

Comments
 (0)