Skip to content

Commit 165d86a

Browse files
committed
Clickable table
1 parent 560a119 commit 165d86a

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

dev/pages/Home.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,12 @@
185185
order-by="id"
186186
:sort-desc="false"
187187
:is-loading="false"
188+
row-clickable
189+
@row-clicked="onRowClicked"
188190
>
189191
<template #td="data">
190192
<span v-if="data.field === 'action'">
191-
<button type="button" class="btn btn-primary">Download</button>
193+
<button type="button" class="btn btn-primary" @click.stop="onTableButtonClicked">Download</button>
192194
</span>
193195
<template v-else>
194196
{{ data.value }}
@@ -358,6 +360,12 @@ export default defineComponent({
358360
// event.preventDefault()
359361
console.log(event)
360362
},
363+
onRowClicked(row: { id: number; name: string }): void {
364+
console.log('Row clicked', row)
365+
},
366+
onTableButtonClicked() {
367+
console.log('Only button clicked (because of @click.stop)')
368+
},
361369
},
362370
})
363371
</script>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bootstrap-vue-wrapper",
3-
"version": "2.1.17",
3+
"version": "2.1.18",
44
"description": "Bootstrap 5 components in Vue3 wrapper.",
55
"module": "./dist/bootstrap-vue-wrapper.js",
66
"types": "./dist/index.d.ts",

src/components/bs-table/BsTable.vue

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
v-for="(item, key) in items"
4141
v-else
4242
:key="key"
43-
:class="item.trClass"
43+
:class="[item.trClass || '', { 'cursor-pointer': rowClickable }]"
44+
@click="$emit('rowClicked', item)"
4445
>
4546
<template v-for="field in fields" :key="field.key">
4647
<td
@@ -118,8 +119,15 @@ export default defineComponent({
118119
type: String,
119120
default: undefined,
120121
},
122+
/**
123+
* row is clickable
124+
*/
125+
rowClickable: {
126+
type: Boolean,
127+
default: false,
128+
},
121129
},
122-
emits: ['orderChanged'],
130+
emits: ['orderChanged', 'rowClicked'],
123131
methods: {
124132
/**
125133
* Is order by active by field?

0 commit comments

Comments
 (0)