forked from labory/knockout-bootstrap-sortable-data-table
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
180 lines (174 loc) · 10.5 KB
/
index.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<!DOCTYPE html>
<html>
<head>
<title>Knockout bootstrap pageable and sortable data table</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" integrity="sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous">
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.0/knockout-debug.js"></script>
<script type="text/javascript" src="ko.dataTable.js"></script>
<script type="text/javascript">
var id = "PersonID",
idName = "ID",
names = ["Name", "Position", "Office", "Extn.", "Start date", "Salary"],
values = names.map(function(name) { return name.toLowerCase().replace(/\W/g, ''); }),
items = [
["Tiger Nixon", "System Architect", "Edinburgh", "5421", "2011/04/25", "$320,800"],
["Garrett Winters", "Accountant", "Tokyo", "8422", "2011/07/25", "$170,750"],
["Ashton Cox", "Junior Technical Author", "San Francisco", "1562", "2009/01/12", "$86,000"],
["Cedric Kelly", "Senior Javascript Developer", "Edinburgh", "6224", "2012/03/29", "$433,060"],
["Airi Satou", "Accountant", "Tokyo", "5407", "2008/11/28", "$162,700"],
["Brielle Williamson", "Integration Specialist", "New York", "4804", "2012/12/02", "$372,000"],
["Herrod Chandler", "Sales Assistant", "San Francisco", "9608", "2012/08/06", "$137,500"],
["Rhona Davidson", "Integration Specialist", "Tokyo", "6200", "2010/10/14", "$327,900"],
["Colleen Hurst", "Javascript Developer", "San Francisco", "2360", "2009/09/15", "$205,500"],
["Sonya Frost", "Software Engineer", "Edinburgh", "1667", "2008/12/13", "$103,600"],
["Jena Gaines", "Office Manager", "London", "3814", "2008/12/19", "$90,560"],
["Quinn Flynn", "Support Lead", "Edinburgh", "9497", "2013/03/03", "$342,000"],
["Charde Marshall", "Regional Director", "San Francisco", "6741", "2008/10/16", "$470,600"],
["Haley Kennedy", "Senior Marketing Designer", "London", "3597", "2012/12/18", "$313,500"],
["Tatyana Fitzpatrick", "Regional Director", "London", "1965", "2010/03/17", "$385,750"],
["Michael Silva", "Marketing Designer", "London", "1581", "2012/11/27", "$198,500"],
["Paul Byrd", "Chief Financial Officer (CFO)", "New York", "3059", "2010/06/09", "$725,000"],
["Gloria Little", "Systems Administrator", "New York", "1721", "2009/04/10", "$237,500"],
["Bradley Greer", "Software Engineer", "London", "2558", "2012/10/13", "$132,000"],
["Dai Rios", "Personnel Lead", "Edinburgh", "2290", "2012/09/26", "$217,500"],
["Jenette Caldwell", "Development Lead", "New York", "1937", "2011/09/03", "$345,000"],
["Yuri Berry", "Chief Marketing Officer (CMO)", "New York", "6154", "2009/06/25", "$675,000"],
["Caesar Vance", "Pre-Sales Support", "New York", "8330", "2011/12/12", "$106,450"],
["Doris Wilder", "Sales Assistant", "Sidney", "3023", "2010/09/20", "$85,600"],
["Angelica Ramos", "Chief Executive Officer (CEO)", "London", "5797", "2009/10/09", "$1,200,000"],
["Gavin Joyce", "Developer", "Edinburgh", "8822", "2010/12/22", "$92,575"],
["Jennifer Chang", "Regional Director", "Singapore", "9239", "2010/11/14", "$357,650"],
["Brenden Wagner", "Software Engineer", "San Francisco", "1314", "2011/06/07", "$206,850"],
["Fiona Green", "Chief Operating Officer (COO)", "San Francisco", "2947", "2010/03/11", "$850,000"],
["Shou Itou", "Regional Marketing", "Tokyo", "8899", "2011/08/14", "$163,000"],
["Michelle House", "Integration Specialist", "Sidney", "2769", "2011/06/02", "$95,400"],
["Suki Burks", "Developer", "London", "6832", "2009/10/22", "$114,500"],
["Prescott Bartlett", "Technical Author", "London", "3606", "2011/05/07", "$145,000"],
["Gavin Cortez", "Team Leader", "San Francisco", "2860", "2008/10/26", "$235,500"],
["Martena Mccray", "Post-Sales support", "Edinburgh", "8240", "2011/03/09", "$324,050"],
["Unity Butler", "Marketing Designer", "San Francisco", "5384", "2009/12/09", "$85,675"]
],
persons = items.map(function(item, identity) {
var res = {};
res[id] = identity + 1;
item.forEach(function(value, i) { res[values[i]] = value; });
return res;
});
function promise(load) {
var d = $.Deferred();
load(d.resolve.bind(d), d.reject.bind(d));
return d.promise();
}
promise.all = $.when.apply.bind($.when, $);
$(function () {
var ExamplePageViewModel = function () {
var self = this;
self.tableViewModel = new ko.dataTable.ViewModel({
columns: [{ name: idName, value: id }].concat(values.map(function(val, i) {
return { value: val, name: names[i] };
})),
sortable: true,
items: persons,
//loader: function () { } || self.getData,
compareBy: id,
page: { sizes: [5,10,25] }
});
};
var vm = new ExamplePageViewModel();
ko.applyBindings(vm);
});
</script>
<style type="text/css">
</style>
</head>
<body>
<div class="container">
<h1>Knockout bootstrap pageable and sortable data table</h1>
<table class="table" data-bind="dataTable: tableViewModel"></table>
<table class="table" data-bind="dataTable: items"></table>
<table class="table" data-bind="dataTable: { items: persons, columns: 'name, position, office', sortable: true }"></table>
</div>
<script type="text/html" id="dt_table_header1">
<thead>
<tr>
<!-- ko if: columns && columns.length -->
<!-- ko foreach: columns -->
<!-- ko if: $data.sortable -->
<th class="dt-header" data-bind="text: name, css: cssClass, style: { width: width }, click: $root.sort"></th>
<!-- /ko -->
<!-- ko ifnot: $data.sortable -->
<th class="dt-header" data-bind="text: name, css: cssClass, style: { width: width }"></th>
<!-- /ko -->
<!-- /ko -->
<!-- /ko -->
<!-- ko if: (!columns || !columns.length) && items().length -->
<!-- ko foreach: $root.toArray(items()[0], 'key') -->
<th data-bind="text: $data"></th>
<!-- /ko -->
<!-- /ko -->
</tr>
</thead>
</script>
<script type="text/html" id="dt_table_body1">
<tbody data-bind="foreach: items">
<tr data-bind="click: $root.selectItem, css: { 'dt-selected': $root.comparator($root.items.selected(), $data) }">
<!-- ko if: $parent.columns && $parent.columns.length -->
<!-- ko foreach: $parent.columns -->
<!-- ko if: template -->
<td data-bind="template: { name: template === true || html ? null : template, data: value == null ? $parent : typeof value == 'function' ? value($parent) : $parent[value] , nodes: html ? ko.utils.parseHtmlFragment(html) : $root.columns.htmlTemplate }"></td>
<!-- /ko -->
<!-- ko ifnot: template -->
<td data-bind="text: typeof value == 'function' ? value($parent) : $parent[value] "></td>
<!-- /ko -->
<!-- /ko -->
<!-- /ko -->
<!-- ko ifnot: $parent.columns && $parent.columns.length -->
<!-- ko foreach: $root.toArray($data, 'value') -->
<td data-bind="text: $data"></td>
<!-- /ko -->
<!-- /ko -->
</tr>
</tbody>
</script>
<script type="text/html" id="dt_table_pager1">
<tfoot>
<tr data-bind="with: page">
<td data-bind="if: sizes.selected, attr: { colspan: $root.columns.length || $root.toArray($root.items()[0], 'key').length || 1 }">
<!-- ko if: sizes().length > 1 -->
<div data-bind="foreach: sizes">
<!-- ko if: $data == $parent.sizes.selected() -->
<span data-bind="text: $data + ' '"></span>
<!-- /ko -->
<!-- ko if: $data != $parent.sizes.selected() -->
<a href="#" data-bind="text: $data + ' ', click: function() { $parent.sizes.selected($data); }"></a>
<!-- /ko -->
</div>
<!-- /ko -->
<nav data-bind="if: count() > 1">
<ul class="pagination">
<li data-bind="css: { disabled: isFirst }">
<a href="#" data-bind="click: prev">«</a>
</li>
<!-- ko foreach: pages -->
<!-- ko if: $data == "ellipsis" -->
<li><span>...</span></li>
<!-- /ko -->
<!-- ko if: $data != "ellipsis" -->
<li data-bind="css: { active: $data === ($parent.index() + 1)}">
<a href="#" data-bind="text: $data, click: $parent.move"></a>
</li>
<!-- /ko -->
<!-- /ko -->
<li data-bind="css: { disabled: isLast }">
<a href="#" data-bind="click: next">»</a>
</li>
</ul>
</nav>
</td>
</tr>
</tfoot>
</script>
</body>
</html>