This file contains 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 id="tabledemo"> | |
<h3>Vue Datatable example</h3> | |
Filter by anything: <input v-model="search"> | |
<hr> | |
<data-table :comments="filteredComments"></data-table> | |
</div> |
This file contains 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
Vue.component('data-table', { | |
render: function (createElement) { | |
return createElement( | |
"table", null, [] | |
) | |
}, | |
props: ['comments'], | |
data() { | |
return { | |
headers: [ | |
{ title: 'Name' }, | |
{ title: 'Email' }, | |
{ title: 'Body' }, | |
], | |
rows: [] , | |
dtHandle: null | |
} | |
}, | |
watch: { | |
comments(val, oldVal) { | |
let vm = this; | |
vm.rows = []; | |
val.forEach(function (item) { | |
let row = []; | |
row.push(item.name); | |
row.push('<a href="mailto://' + item.email + '">' + item.email + '</a>'); | |
row.push(item.body); | |
vm.rows.push(row); | |
}); | |
vm.dtHandle.clear(); | |
vm.dtHandle.rows.add(vm.rows); | |
vm.dtHandle.draw(); | |
} | |
}, | |
mounted() { | |
let vm = this; | |
vm.dtHandle = $(this.$el).DataTable({ | |
columns: vm.headers, | |
data: vm.rows, | |
searching: true, | |
paging: true, | |
info: false | |
}); | |
} | |
}); | |
new Vue({ | |
el: '#tabledemo', | |
data: { | |
comments: [], | |
search: '' | |
}, | |
computed: { | |
filteredComments: function () { | |
let self = this | |
let search = self.search.toLowerCase() | |
return self.comments.filter(function (comments) { | |
return comments.name.toLowerCase().indexOf(search) !== -1 || | |
comments.email.toLowerCase().indexOf(search) !== -1 || | |
comments.body.toLowerCase().indexOf(search) !== -1 | |
}) | |
} | |
}, | |
mounted() { | |
let vm = this; | |
$.ajax({ | |
url: 'https://jsonplaceholder.typicode.com/comments', | |
success(res) { | |
vm.comments = res; | |
} | |
}); | |
} | |
}); |
This file contains 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> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> | |
<script src="//cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script> |
This file contains 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="//cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css" rel="stylesheet" /> |
A Pen by Edward Lance Lorilla on CodePen.
4 Comments
Can you purpose us a tutorial on multiple dropdown menu using vue js and laravel...
Thank you