-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathexample.html
122 lines (114 loc) · 3.6 KB
/
example.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Vue DataTable Component Example</title>
<link href="//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
<link href="//cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
</head>
<body>
<div id="app" class="container" style="margin-top:50px">
<button
class="btn btn-default btn-xs btn-block"
onclick="location.reload()">
Click me to force reload current page, to see how components keep in sync with URL's query string
</button>
<br>
<router-view></router-view>
<hr>
<data-table
:columns="columns"
:data="tableData"
:total="total"
:checked-ids.sync="checkedIds"
:config="{ idField: 'uid', searchInput: 'User ID / Nickname' }">
<div class="form-inline" slot="opt">
<button class="btn btn-xs btn-default" @click="$broadcast('TOGGLE_ALL', true)">Check All</button>
<button class="btn btn-xs btn-default" @click="$broadcast('TOGGLE_ALL')">Uncheck All</button>
<code>Checked ID: {{ checkedIds | json }}</code>
</div>
</data-table>
</div>
<script src="//cdn.bootcss.com/jquery/2.1.4/jquery.min.js"></script>
<script src="//cdn.bootcss.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="//cdn.bootcss.com/vue/1.0.28/vue.min.js"></script>
<script src="//cdn.bootcss.com/vue-router/0.7.13/vue-router.min.js"></script>
<script src="./dist/vue-datatable-component.min.js"></script>
<script>
// setup
Vue.use(VueRouter);
Vue.config.devtools = true;
// table-cell-component for `status` field
var Status = {
props: ['value'],
computed: {
status () {
return ['Not bad', 'Good', 'Perfect'][this.value];
}
},
template: '<span>{{ status }}</span>'
};
// table-cell-component for printing user info to console
var PrintToConsole = {
props: ['row'],
methods: {
print: function () {
console.info(JSON.stringify(this.row));
}
},
template: '<button class="btn btn-default fa fa-print" @click="print"></button>'
};
// root component
var App = {
components: {
DataTable: VueDataTable,
// table-cell-components below
Status: Status,
Print: PrintToConsole
},
data: function () {
return {
columns: [
{ field: 'uid', title: 'User ID', sort: true },
{ field: 'name', title: 'Nickname' },
{ field: 'age', title: 'Age', sort: true },
{ field: 'status', title: 'Current mood', component: 'Status' },
{ field: '_whatever_name_', title: 'Console', component: 'Print' }
],
tableData: [
{ uid: 1, name: 'Ken', age: 22, status: 0 },
{ uid: 2, name: 'John', age: 23, status: 1 },
{ uid: 3, name: 'Mike', age: 24, status: 2 },
{ uid: 4, name: 'May', age: 25, status: 0 },
{ uid: 5, name: 'Kate', age: 26, status: 1 },
{ uid: 6, name: 'Ben', age: 27, status: 2 },
{ uid: 7, name: 'Amy', age: 28, status: 0 },
{ uid: 8, name: 'Susan', age: 29, status: 1 },
{ uid: 9, name: 'Paker', age: 30, status: 2 },
{ uid: 10, name: 'Taylor', age: 31, status: 0 }
],
checkedIds: [], // for multi-select
total: 50
};
}
};
// run app!
var router = new VueRouter();
router.map({
'/': {
component: {
route: {
data: function () {
// fetch data with this.$route.query...
}
},
template: '<code>$route.query: {{ $route.query | json }}</code>'
}
}
});
router.start(App, '#app');
// table components will keep in sync with URL's query string
// try reloading page to test this feature
</script>
</body>
</html>