Answer the question
In order to leave comments, you need to log in
How to make the checkbox react to clicks (bootstrap-vue)?
I am using bootstrap vue. I need to make a table where the first column is a checkbox. In the columns where tbody I could implement, but it doesn’t work in thead, the checkbox itself is there, but when pressed, it does not change its state. The isActive field is responsible for the state of the checkboxes.
Implementation code
<template>
<div>
<b-table striped hover :items="items" :fields="fileds">
<template slot="isActive" slot-scope="data">
<b-form-checkbox></b-form-checkbox>
</template>
<template slot="HEAD_isActive" slot-scope="data">
<b-form-checkbox></b-form-checkbox>
</template>
</b-table>
</div>
</template>
<script>
const fileds = [
'isActive',
'email',
{
key: 'name',
label: 'Наименование'
},
{
key: 'phone',
label: 'Телефон'
},
{
key: 'responsible',
label: 'Ответственный'
},
{
key: 'deals',
label: 'Сделки'
}
];
const items = [
{ isActive: true, email: 40, name: 'Dickerson', phone: 'Macdonald', responsible: 'Макаров', deals: 'Купил' },
{ isActive: true, email: 40, name: 'Dickerson', phone: 'Macdonald', responsible: 'Макаров', deals: 'Продал' },
{ isActive: true, email: 40, name: 'Dickerson', phone: 'Macdonald', responsible: 'Макаров', deals: 'Купил' },
{ isActive: true, email: 40, name: 'Dickerson', phone: 'Macdonald', responsible: 'Макаров', deals: 'Продал' },
];
export default {
name: "BaseTable",
data() {
return {
fileds: fileds,
items: items
}
}
}
</script>
<style scoped>
</style>
Answer the question
In order to leave comments, you need to log in
In columns where tbody I was able to implement
<template slot="isActive" slot-scope="{ item }">
<b-form-checkbox v-model="item.isActive"></b-form-checkbox>
</template>
but it doesn't work in thead
true
if all checkboxes are true
; setter - assign the passed value to all checkboxes:checkedAll: {
get() {
return this.items.every(n => n.isActive);
},
set(val) {
this.items.forEach(n => n.isActive = val);
},
},
<template slot="HEAD_isActive" slot-scope="data">
<b-form-checkbox
@click.native.stop
:checked="checkedAll"
@change="checkedAll = $event"
></b-form-checkbox>
</template>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question