A Pen by Edward Lance Lorilla on CodePen.
Last active
January 17, 2023 14:50
-
-
Save edwardlorilla/d8cfe1d40f2514ca13c8eaaae7657a3e to your computer and use it in GitHub Desktop.
HOW TO SELECT VUEJS CHECK ALL UNCHECK ALL CHECKBOXES
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="container"> | |
<div id="app"> | |
<h4>Names</h4> | |
<div> | |
<table class="table"> | |
<tr> | |
<th><input type="checkbox" v-model="checkAll"></th> | |
<th align="center">ID</th> | |
<th align="center">Names</th> | |
</tr> | |
<tr v-for="lang in langs"> | |
<td> | |
<input type="checkbox" v-model="checked" :value="lang.id" number> | |
</td> | |
<td> {{ lang.id }}</td> | |
<td> {{ lang.name }}</td> | |
</tr> | |
</table> | |
</div> | |
</div> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
new Vue({ | |
data: { | |
langs: [ | |
{ "id": "1", "name": "Edward"}, | |
{ "id": "2", "name": "Lance"}, | |
{ "id": "3", "name": "Arellano"}, | |
{ "id": "4", "name": "Lorilla"}, | |
], | |
checked: [] | |
}, | |
computed: { | |
checkAll: { | |
get: function () { | |
return this.langs ? this.checked.length == this.langs.length : false; | |
}, | |
set: function (value) { | |
var checked = []; | |
if (value) { | |
this.langs.forEach(function (lang) { | |
checked.push(lang.id); | |
}); | |
} | |
this.checked = checked; | |
} | |
} | |
} | |
}).$mount('#app'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17-beta.0/vue.js"></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" /> |
A Pen by Edward Lance Lorilla on CodePen.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hello Edward thank you for thsi solution
I would appreciate it if you can convert this code to Vue 3 with setup script