"jQuery Table Page Plugin"
Bootstrap 3.3.0 Snippet by SeanWessell

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
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<!------ Include the above in your HEAD tag ---------->
<div class="container">
<h3>Using jQuery plugin allows you to apply paging to standard html table.</h3>
The default number of pages is 10 but you can pass a number to the function to have more or less items per page.<br /><br />
<h4>To Initialize the table use either of the following:</h4>
<pre><code>
$('#tableid').page();
<strong>OR</strong>
$('#tableid').page(15);
</code></pre>
</p>
<div class="row">
<div class="col-sm-10 col-sm-offset-1">
<h3>Table Paging</h3>
<table id="zipTable" class="table">
<tr>
<th>Zipcode</th>
<th>City</th>
<th>State</th>
</tr>
<tr>
<td>00401</td>
<td>Pleasantville</td>
<td>NY</td>
</tr>
<tr>
<td>00501</td>
<td>Holtsville</td>
<td>NY</td>
</tr>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
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
//Beginning of plugin
(function ($) {
$.fn.page = function (PageSize) {
$(this).addClass("page-table")
var tableId = $(this).attr("id");
//if id is not defined for table. Do Nothing.
if (typeof tableId == 'undefined') {
return this;
};
//Check for controls for this table and remove
$('.pagination[for="' + tableId + '"]').remove();
//Check for valid variable for pageSize if not set to default of 10
if (typeof PageSize == 'number') {
PageSize = parseInt(PageSize);
} else if (typeof PageSize == 'string') {
if ($.isNumeric(PageSize) == true) {
PageSize = parseInt(PageSize);
} else {
PageSize = 10;
}
} else {
PageSize = 10;
}
//Add pagination <ul> to hold controls
$(this).after('<ul class="pagination" for="' + tableId + '"></ul>');
//Add a pager control for each page
var currpage = 1;
var item = 1;
$(this).find('tr:has(td)').each(function () {
$(this).attr('data-page', currpage);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Related: See More


Questions / Comments: