-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathexample.html
More file actions
200 lines (187 loc) · 7.74 KB
/
example.html
File metadata and controls
200 lines (187 loc) · 7.74 KB
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>ko.pager example</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<script src="js/jquery-1.8.2.min.js" type="text/javascript"></script>
<script src="js/knockout-2.2.0.js" type="text/javascript"></script>
<script src="js/bootstrap.min.js" type="text/javascript"></script>
<script src="js/ko.pager.js" type="text/javascript"></script>
<link href="css/bootstrap.css" rel="stylesheet">
<style>
body
{
padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
}
</style>
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script type="text/javascript">
var ViewModel = function () {
var self = this;
// only for example, used to demonstrate setting the total item count from a service call.
self.SetTotalResults = ko.observable(0);
// holds the total item count
self.TotalResults = ko.observable();
// actual pager, used to bind to the pager's template
// first parameter must be an observable or function which returns the current 'total item count'.
// it is wrapped in a ko.computed inside the pager.
self.Pager = ko.pager(self.TotalResults);
// Subscribe to current page changes.
self.Pager().CurrentPage.subscribe(function () {
self.search();
});
self.search = function () {
// simulate a search
// ie.:
/*
var maximumRows = self.Pager().PageSize(),
searchText = self.SearchText(),
startIndex = (self.Pager().CurrentPage() - 1) * maximumRows;
myService.search(searchText, startIndex, maximumRows)
.done(function(result) {
// set your own results etc...
self.TotalResults(result.totalItemCount);
}
*/
// setting 'total results'. This should be in your result callback
// in this example we grab it from the form.
var totalItemCount = self.SetTotalResults();
self.TotalResults(totalItemCount);
}
} // /ViewModel
$(function () {
ko.applyBindings(new ViewModel(), $('body')[0]);
});
</script>
</head>
<body>
<div class="container">
<h1>ko.pager Example:</h1>
<form class="form-horizontal">
<h3>Configure pager:</h3>
<div class="control-group">
<label class="control-label" for="CurrentPage">CurrentPage</label>
<div class="controls">
<input type="text" id="CurrentPage" data-bind="value: Pager().CurrentPage">
<p>
Subscribe to this property to trigger your search function.<br />
It is changed when the user clicks a page.
</p>
</div>
</div>
<div class="control-group">
<label class="control-label" for="PageSize">PageSize</label>
<div class="controls">
<input type="text" id="PageSize" data-bind="value: Pager().PageSize">
<p>
Define page size for correct calculation. Defaults to <strong>10</strong>.
</p>
</div>
</div>
<div class="control-group">
<label class="control-label" for="PageSlide">PageSlide</label>
<div class="controls">
<input type="text" id="PageSlide" data-bind="value: Pager().PageSlide">
<p>
Defines the page slide effect size. Defaults to <strong>2</strong>.
</p>
</div>
</div>
<hr />
<h3>Search:</h3>
<div class="control-group">
<label class="control-label" for="TotalItemCount">Total Item Count</label>
<div class="controls">
<p>
<strong>Set this to a number greater than 0 to show the pager.</strong>
</p>
<input type="text" id="TotalItemCount" data-bind="value: SetTotalResults">
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="button" class="btn" data-bind="click: search">Search</button>
</div>
</div>
<p>
In this example, only the pager is shown. No grid or results of any kind. Also the pager's template is using bootstrap to style it a bit.
</p>
</form>
<hr />
<!-- ko ifnot:Pager().TotalItemCount() > 0 -->
<p>
No results found
</p>
<!-- /ko -->
<!-- ko if:Pager().TotalItemCount() > 0 -->
<div class="pagination" data-bind="template:{ name: 'tpl-pager', data: Pager }">
</div>
<!-- /ko -->
</div>
<!-- /container -->
<script type="text/html" id="tpl-pager">
<div class="pagexofx">
<span data-bind="text: FirstItemIndex"></span>
-
<span data-bind="text: LastItemIndex"></span>
of
<strong>
<span data-bind="text: TotalItemCount"></span>
</strong>
total results.
</div>
<ul>
<!-- ko if:CurrentPage() === 1 -->
<li class="disabled">
<a href="#" class="disabledPage">««</a></li>
<!-- /ko -->
<!-- ko ifnot:CurrentPage() === 1 -->
<li>
<a href="#" data-bind="click: function(){ selectPage(1); }">««</a></li>
<!-- /ko -->
<!-- ko if:HasPrevPage -->
<li>
<a href="#" data-bind="click: function(){ selectPage(CurrentPage() - 1); }">«</a></li>
<!-- /ko -->
<!-- ko ifnot:HasPrevPage -->
<li class="disabled">
<a href="#" class="disabledPage">«</a></li>
<!-- /ko -->
<!-- ko foreach:Pages -->
<!-- ko if:$data === $parent.CurrentPage() -->
<li class="active">
<span class="currentPage" data-bind="text: $data"></span>
</li>
<!-- /ko -->
<!-- ko if:$data !== $parent.CurrentPage() -->
<li>
<a href="#" data-bind="text: $data, click: function(){ $parent.selectPage($data); }"></a>
</li>
<!-- /ko -->
<!-- /ko -->
<!-- ko if:HasNextPage -->
<li>
<a href="#" data-bind="click: function(){ selectPage(CurrentPage() + 1); }">»</a></li>
<!-- /ko -->
<!-- ko ifnot:HasNextPage -->
<li class="disabled">
<a href="#" class="disabledPage">»</a></li>
<!-- /ko -->
<!-- ko ifnot:CurrentPage() === LastPage() -->
<li>
<a href="#" data-bind="click: function(){ selectPage(LastPage()); }">»»</a></li>
<!-- /ko -->
<!-- ko if:CurrentPage() === LastPage() -->
<li class="disabled">
<a href="#" class="disabledPage">»»</a></li>
<!-- /ko -->
</ul>
</script>
</body>
</html>