Im trying to implement Vue.js + jQuery's DataTables but there's a weird things happening.
Check this fiddle on firefox (not working on chrome): http://jsfiddle.net/chrislandeza/xgv8c01y/
when I change the state of DataTable (e.g. sort, search, etc.):
- Newly added data on the list disappears
- The DOM is not reading the directives or the vue properties
I'm pretty sure anyone who tried to mix vue.js+datatables experienced this problem. what did you do to solve this?
or is there a pure Vue.js script/plugin that has the same (or close) functionality like jquery's DataTable? (pagination, searching, sorting, number of entries to show, etc.).
here's the code from the fiddle above:
HTML:
<div class='container-fluid' id="app"> <div class='row'> <div class='col-md-9'> <table class="table table-bordered" id="app-datatable"> <thead> <tr> <th>Name</th> <th>Age</th> <th></th> </tr> </thead> <tbody> <tr v-repeat="user: users"> <td>{{ user.name }}</td> <td>{{ user.age }}</td> <td> <button type="button" v-on="click: foo(user)">Action</button> </td> </tr> </tbody> </table> </div> <div class='col-md-3'> <div class="form-group"> <label>Name</label> <input type="text" class="form-control" v-model="newUser.name" > </div> <div class="form-group"> <label>Age</label> <input type="name" class="form-control" v-model="newUser.age" > </div> <button type="submit" class="btn btn-primary" v-on="click: addUser()">Add</button> </div> </div> </div> JavaScript:
$(document).ready(function () { var dT = $('#app-datatable').DataTable(); }); var vm = new Vue({ el: '#app', data: { newUser: {}, users: [ {name: 'Chris', age: 1}, {name: 'John', age: 2} ] }, methods:{ addUser: function(){ this.users.push(this.newUser); this.newUser = {}; }, foo: function(user){ console.log(user.name); } } }); any suggestions are greatly appreciated.