This repository has been archived by the owner on Mar 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
441 lines (425 loc) · 18.3 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>ajaxPager Demo</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<!-- Le styles -->
<link href="resources/scripts/bootstrap/css/bootstrap.css" rel="stylesheet">
<style type="text/css">
body {
padding-top: 60px;
padding-bottom: 40px;
}
</style>
<link href="resources/styles/pagingbar.css" rel="stylesheet">
<link href="resources/scripts/google-code-prettify/prettify.css" rel="stylesheet">
<!-- Le 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]-->
</head>
<body>
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container-fluid">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="http://examples.cutterscrossing.com/ajaxPager">ajaxPager</a>
<div class="nav-collapse">
<ul class="nav">
<li class="active"><a href="#demo">Demo</a></li>
<li><a href="#docs">Documentation</a></li>
<li><a href="#options">Options</a></li>
</ul>
<!-- <p class="navbar-text pull-right">Logged in as <a href="#">username</a></p> -->
</div>
</div>
</div>
</div>
<div class="container-fluid">
<div class="well clearfix">
<p>The <strong>ajaxPager</strong> is a <a href="http://www.jquery.com" target="_blank">JQuery</a> + <a href="http://twitter.github.com/bootstrap/index.html" target="_blank">Bootstrap</a> plugin that creates a pagination control bar, according to configuration, that will make remote requests for data. The control then passes the response to a developer defined method to create the output. In the example, we used the <a href="http://handlebarsjs.com/" target="_blank">Handlebars</a> templating engine to create display items of each record in a returned JSON recordset.</p>
<p>ajaxPager is available on <a href="https://github.com/cutterbl/ajaxPager" target="_blank">GitHub</a>.</p>
</div>
<!--- This is here for reference, to test new things on what would become new generated display
<div class="container-fluid">
<div class="row-fluid">
<div class="span2"> </div>
<div class="span8">
<div class="pagingbar">
<div class="pagingbar-inner">
<div class="container">
<div class="nav-collapse">
<ul class="nav nav-pills">
<li><a href="#">|«</a></li>
<li class="divider-vertical"></li>
<li><a href="#">«</a></li>
<li class="divider-vertical"></li>
</ul>
<form name="jump" class="navbar-form pull-left">
<strong>Page</strong> <input type="text" name="page" value="1" style="width:25px;" /> <strong>of 12</strong>
</form>
<ul class="nav nav-pills">
<li class="divider-vertical"></li>
<li><a href="#" class="disabled">»</a></li>
<li class="divider-vertical"></li>
<li><a href="#" class="disabled">»|</a></li>
<li class="divider-vertical"></li>
</ul>
<span class="nav pull-right navbar-text">
<strong>Showing Records 1 - 25 of 139</strong>
</span>
</div>
</div>
</div>
</div>
<div class="pagingbar">
<div class="container">
<div class="nav-collapse">
<ul class="nav nav-pills">
<li><a href="#">|«</a></li>
<li class="divider-vertical"></li>
<li><a href="#">«</a></li>
<li class="divider-vertical"></li>
</ul>
<form name="jump" class="navbar-form pull-left">
<strong>Page</strong> <input type="text" name="page" value="1" style="width:25px;" /> <strong>of 12</strong>
</form>
<ul class="nav nav-pills">
<li class="divider-vertical"></li>
<li><a href="#">»</a></li>
<li class="divider-vertical"></li>
<li><a href="#">»|</a></li>
<li class="divider-vertical"></li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Dropdown<b class="caret"></b></a>
<ul class="dropdown-menu">
<li>
<a href="#">Action</a>
</li>
<li>
<a href="#">Another action</a>
</li>
<li>
<a href="#">Something else here</a>
</li>
<li class="divider"></li>
<li class="nav-header">Nav header</li>
<li>
<a href="#">Separated link</a>
</li>
<li>
<a href="#">One more separated link</a>
</li>
</ul>
</li>
</ul>
<span class="pull-right navbar-text" style="margin-right:20px;">
<strong>Showing Records 1 - 25 of 139</strong>
</span>
</div>
</div>
</div>
</div>
</div>
</div> --->
<div class="container-fluid">
<div class="row-fluid">
<div class="span2"> </div>
<div class="span8">
<a name="demo"></a><h2>Demo</h2>
<div id="testCont"> This is where the paging content loads...</div>
</div>
</div>
<div class="row-fluid">
<div class="span2"> </div>
<div class="span8 well">
<a name="docs"></a><h2>Documentation</h2>
<p>The ajaxPager component requires <a href="http://www.jquery.com" target="_blank">JQuery</a> and <a href="http://twitter.github.com/bootstrap/index.html" target="_blank">Bootstrap</a> be loaded in your template, as well as the stylesheet and script used for the ajaxPager.</p>
<pre class="prettyprint linenums lang-html">
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<head>Our Test Case</head>
<link href="/resources/scripts/bootstrap/css/bootstrap.css" rel="stylesheet">
<link href="/resources/styles/custom/subnav.css" rel="stylesheet">
<!-- Le 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]-->
</head>
<body>
<div class="container-fluid">
<div class="row-fluid">
<div class="span2"> </div>
<div class="span8">
<!-- Our Paged Container -->
<div id="testCont"> This is where the paging content loads...</div>
</div>
</div>
</div>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js"></script>
<script src="/resources/scripts/bootstrap/js/bootstrap.js"></script>
<script type="text/javascript" src="/resources/scripts/bootstrap.ajaxpager-0.8.js"></script>
<!-- Our custom script for our demo -->
<script type="text/javascript" src="/resources/scripts/custom/pagingTest.js"></script>
<!-- Use whatever templating method you want -->
<!-- We'll use Handlebars JS for a templating engine in our example -->
<script src="/resources/scripts/handlebars-1.0.0.0.beta.6.js"></script>
<script id="line-template" type="text/x-handlebars-template">
<!-- Handlebars JS Template -->
</script>
</body>
</html>
</pre>
<p>In our example we're using <a href="http://handlebarsjs.com/" target="_blank">HandlebarsJS</a> as our templating engine, but you can use whatever engine you like for rendering your output. The ajaxPager will:</p>
<ol type="a">
<li>Create the pager bar(s) for your container element</li>
<li>Make the ajax request</li>
<li>Track the page, record count and total records (from the response)</li>
<li>Take the response and process it through your method</li>
<li>Render your output in the primary element</li>
</ol>
<p>It does most of this behind the scenes. All that's required is instantiating the ajaxPager with a valid configuration.</p>
<a name="options"></a><h2>Options</h2>
<h3>General Pager Display</h3>
<dl class="dl-horizontal">
<dt>position</dt>
<dd>top|bottom|both - the position(s) of the pager bars in relation to the container element (defaults to "top")</dd>
<dt>class</dt>
<dd>any additional classes to add to the pager bars when rendered</dd>
<dt>stripedrows</dt>
<dd>will apply a 'striped-row' class to every other element added to the container on data load (defaults to "false")</dd>
<dt>loadtext</dt>
<dd>the text that displays on the loading alert (defaults to "Loading")</dd>
</dl>
<pre class="prettyprint linenums lang-js">
$(document).ready(function(){
// Other stuff
$('div#testCont').ajaxPager({
position: 'both',
class: 'someclass',
stripedrows: true,
loadtext: 'Retrieving your data...',
...
});
});
</pre>
<h3>General Paging</h3>
<dl class="dl-horizontal">
<dt>page</dt>
<dd>the page of results to display (defaults to "1")</dd>
<dt>limit</dt>
<dd>the number of records to display in a page (defaults to "25")</dd>
<dt>limitdd</dt>
<dd>boolean to determine if the "Limit" dropdown will display (defaults to "true")</dd>
<dt>limitoptions</dt>
<dd>an array of numeric values, dilineating the number of records per page (defaults to "[25,50,75,100]")</dd>
<dt>sortcolumn</dt>
<dd>the column on which to initially sort results</dd>
<dt>sortdir</dt>
<dd>asc|desc - the sort direction (defaults to "asc" if "sortcolumn" is defined)</dd>
<dt>sortby</dt>
<dd>an object of key/value pairs, equating to a column name (key) and it's display label (value), to be used in the "Sort By" dropdown on the pager bar(s). If an object is not passed then the "Sort By" dropdown is ommitted.</dd>
<dt>searchtext</dt>
<dd>a json string of key/value pairs to pass to the remote method for filtering</dd>
</dl>
<pre class="prettyprint linenums lang-js">
$(document).ready(function(){
//Other stuff
$('div#testCont').ajaxPager({
...
page: 1,
limit: 10,
limitdd: true,
limitoptions: [10,20,30,40,50],
sortcolumn: 'title',
sortdir: 'asc',
sortby: {
title: 'Title',
posted: 'Date Posted',
views: 'Views'
},
searchtext: '{"title":"ColdFusion"}',
...
});
});
</pre>
<h3>Remote Request</h3>
<dl class="dl-horizontal">
<dt>ajaxoptions</dt>
<dd>standard options of a <a href="http://api.jquery.com/jQuery.ajax/" target="_blank">JQuery Ajax</a> request
<dl class="dl-horizontal">
<dt>url</dt>
<dd>the url to which the request is sent</dd>
<dt>type</dt>
<dd>the method type of the request (defaults to "POST")</dd>
<dt>data</dt>
<dd>an object for any extra values to be passed along with the request</dd>
<dt>dataType</dt>
<dd>the data type of the expected request response (defaults to "json")</dd>
</dl>
</dd>
<dt>reader</dt>
<dd>an object, the parameters of which define the returned response (for json based or xml(?) responses)
<dl class="dl-horizontal">
<dt>success</dt>
<dd>key of the "success" indicator</dd>
<dt>message</dt>
<dd>key of the "message" indicator, used when "success" is false to indicate an error</dd>
<dt>totalpages</dt>
<dd>server response indicating the total number of pages of available records for the search criteria passed</dd>
<dt>totalrecords</dt>
<dd>server response indicating the total number of records available that meet the search criteria passed</dd>
<dt>root</dt>
<dd>dot notation path to the root key of the dataset (record set) associated with the response</dd>
</dl>
</dd>
<dt>params</dt>
<dd>key/pairs that allow the developer to override the key names, of default data, that are passed in each request (each defaults to their key name)
<dl class="dl-horizontal">
<dt>start</dt>
<dd>the first record being requested</dd>
<dt>limit</dt>
<dd>the number of records to be returned in each response</dd>
<dt>page</dt>
<dd>the page of data being requested</dd>
<dt>sort</dt>
<dd>the column by which the data is currently being sorted by</dd>
<dt>dir</dt>
<dd>the direction by which the data is currently being sorted by</dd>
<dt>search</dt>
<dd>a json string denoting search criteria beyond those already mentioned</dd>
</dl>
</dd>
<dt>renderoutput</dt>
<dd>a function that takes the server response (function(data)) and returns the formatted data to be displayed within the container</dd>
</dl>
<pre class="prettyprint linenums lang-js">
$(document).ready(function(){
// Reference and Compile the Handlebars template
var tplContent = $('#line-template').html();
var lineTpl = Handlebars.compile(tplContent);
$('div#testCont').ajaxPager({
...
ajaxoptions: {
url: 'com/cc/Blog/Entries.cfc',
data: {
method: 'getEntries',
returnFormat: 'json'
},
dataType: 'json'
},
params: {
page: 'pageIndex',
limit: 'pageSize',
sort: 'sortCol',
dir: 'sortDir'
},
reader: {
success: 'success',
message: 'message',
totalpages: 'pageCount',
totalrecords: 'recordCount',
root: 'data'
},
renderoutput: lineTpl, // Apply the Handlebars template to the output
...
});
});
</pre>
<h3>Events</h3>
<dl class="dl-horizontal">
<dt>listeners</dt>
<dd>an object containing function methods that fire when specific events occur
<dl class="dl-horizontal">
<dt>init</dt>
<dd>function(event) - fires when the component has initialized, after pagers have been added, but prior to bindings being set in the "render" event</dd>
<dt>render</dt>
<dd>function(event) - fires once the pagers have been rendered, just prior to all internal bindings being put into place</dd>
<dt>preprocess</dt>
<dd>function(response) - fires upon successful request, prior to any other processing (good for data conversions prior to creating output)</dd>
<dt>beforeload</dt>
<dd>function(event) - fires after "renderoutput", but prior to output being added into the container, typically for the removal of any developer defined bindings</dd>
<dt>load</dt>
<dd>function(event) - fires after the formatted output has been added to the container, typically for adding bindings to new content</dd>
<dt>destroy</dt>
<dd>function(event) - fires in component's "destroy" method, just prior to the component's removal of bindings, data, and display</dd>
</dl>
</dd>
</dl>
<pre class="prettyprint linenums lang-js">
$(document).ready(function(){
...
var testHandler = function (){
console.log(arguments);
}
$('div#testCont').ajaxPager({
...
listeners: {
init: testHandler,
render: testHandler,
preprocess: $.serializeCFJSON, // Convert native CF query json to standard name/value json
beforeload : testHandler,
load : testHandler,
destroy : testHandler
}
});
});
</pre>
<p>The only thing you really require now is a template for your templating engine. Some kind of definition for how you want each item of the dataset to be rendered. For the above example we used something very basic, using the <a href="http://www.handlebarsjs.com" target="_blank">Handlebars JS</a> engine.</p>
<pre class="prettyprint linenums lang-html">
<script id="line-template" type="text/x-handlebars-template">
{{#each data}}
<div class="row-fluid data-row" id="{{this.id}}">
<div class="span2">
{{this.posted}}
</div>
<div class="span9">
{{this.title}}
</div>
<div class="span1">
{{this.views}}
</div>
</div>
{{/each}}
</script>
</pre>
<p>That's it! Nothing to it! The pager will keep track of what page you're on, change your record counts, make and process your ajax requests, all behind the scenes.</p>
</div>
</div>
</div><!--/.fluid-container-->
<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js"></script>
<script src="resources/scripts/bootstrap/js/bootstrap.js"></script>
<script src="resources/scripts/handlebars-1.0.0.0.beta.6.js"></script>
<script src="resources/scripts/jquery-plugins/serializeCFJSON/serializeCFJSON-0.1.min.js"></script>
<script src="resources/scripts/bootstrap.ajaxpager-0.8.min.js"></script>
<script src="resources/scripts/custom/pagingTest.js"></script>
<script src="resources/scripts/google-code-prettify/prettify.js"></script>
<script id="line-template" type="text/x-handlebars-template">
{{#each getEntries}}
<div class="row-fluid data-row" id="{{this.id}}">
<div class="span2">
{{this.posted}}
</div>
<div class="span9">
{{this.title}}
</div>
<div class="span1">
{{this.views}}
</div>
</div>
{{/each}}
</script>
</body>
</html>