table.html 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <meta name="viewport" content="width=device-width, initial-scale=1">
  5. <title>Snippet - Bootsnipp.com</title>
  6. <link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet">
  7. <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
  8. <script type="text/javascript" src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
  9. <style>
  10. .table-responsive {height:500px;}
  11. </style>
  12. <script type="text/javascript">
  13. $.fn.pageMe = function(opts){
  14. var $this = this,
  15. defaults = {
  16. perPage: 7,
  17. showPrevNext: false,
  18. hidePageNumbers: false
  19. },
  20. settings = $.extend(defaults, opts);
  21. var listElement = $this;
  22. var perPage = settings.perPage;
  23. var children = listElement.children();
  24. var pager = $('.pager');
  25. if (typeof settings.childSelector!="undefined") {
  26. children = listElement.find(settings.childSelector);
  27. }
  28. if (typeof settings.pagerSelector!="undefined") {
  29. pager = $(settings.pagerSelector);
  30. }
  31. var numItems = children.size();
  32. var numPages = Math.ceil(numItems/perPage);
  33. pager.data("curr",0);
  34. if (settings.showPrevNext){
  35. $('<li><a href="#" class="prev_link">«</a></li>').appendTo(pager);
  36. }
  37. var curr = 0;
  38. while(numPages > curr && (settings.hidePageNumbers==false)){
  39. $('<li><a href="#" class="page_link">'+(curr+1)+'</a></li>').appendTo(pager);
  40. curr++;
  41. }
  42. if (settings.showPrevNext){
  43. $('<li><a href="#" class="next_link">»</a></li>').appendTo(pager);
  44. }
  45. pager.find('.page_link:first').addClass('active');
  46. pager.find('.prev_link').hide();
  47. if (numPages<=1) {
  48. pager.find('.next_link').hide();
  49. }
  50. pager.children().eq(1).addClass("active");
  51. children.hide();
  52. children.slice(0, perPage).show();
  53. pager.find('li .page_link').click(function(){
  54. var clickedPage = $(this).html().valueOf()-1;
  55. goTo(clickedPage,perPage);
  56. return false;
  57. });
  58. pager.find('li .prev_link').click(function(){
  59. previous();
  60. return false;
  61. });
  62. pager.find('li .next_link').click(function(){
  63. next();
  64. return false;
  65. });
  66. function previous(){
  67. var goToPage = parseInt(pager.data("curr")) - 1;
  68. goTo(goToPage);
  69. }
  70. function next(){
  71. goToPage = parseInt(pager.data("curr")) + 1;
  72. goTo(goToPage);
  73. }
  74. function goTo(page){
  75. var startAt = page * perPage,
  76. endOn = startAt + perPage;
  77. children.css('display','none').slice(startAt, endOn).show();
  78. if (page>=1) {
  79. pager.find('.prev_link').show();
  80. }
  81. else {
  82. pager.find('.prev_link').hide();
  83. }
  84. if (page<(numPages-1)) {
  85. pager.find('.next_link').show();
  86. }
  87. else {
  88. pager.find('.next_link').hide();
  89. }
  90. pager.data("curr",page);
  91. pager.children().removeClass("active");
  92. pager.children().eq(page+1).addClass("active");
  93. }
  94. };
  95. $(document).ready(function(){
  96. $('#myTable').pageMe({pagerSelector:'#myPager',showPrevNext:true,hidePageNumbers:false,perPage:7});
  97. });
  98. </script>
  99. </head>
  100. <body>
  101. <div class="container">
  102. <div class="row">
  103. <div class="table-responsive">
  104. <table class="table table-hover">
  105. <thead>
  106. <tr>
  107. <th>#</th>
  108. <th>Table heading</th>
  109. <th>Table heading</th>
  110. <th>Table heading</th>
  111. <th>Table heading</th>
  112. <th>Table heading</th>
  113. <th>Table heading</th>
  114. </tr>
  115. </thead>
  116. <tbody id="myTable">
  117. <tr style="display: none;">
  118. <td>1</td>
  119. <td>Table cell</td>
  120. <td>Table cell</td>
  121. <td>Table cell</td>
  122. <td>Table cell</td>
  123. <td>Table cell</td>
  124. <td>Table cell</td>
  125. </tr>
  126. <tr style="display: none;">
  127. <td>2</td>
  128. <td>Table cell</td>
  129. <td>Table cell</td>
  130. <td>Table cell</td>
  131. <td>Table cell</td>
  132. <td>Table cell</td>
  133. <td>Table cell</td>
  134. </tr>
  135. <tr style="display: none;">
  136. <td>3</td>
  137. <td>Table cell</td>
  138. <td>Table cell</td>
  139. <td>Table cell</td>
  140. <td>Table cell</td>
  141. <td>Table cell</td>
  142. <td>Table cell</td>
  143. </tr>
  144. <tr style="display: none;">
  145. <td>4</td>
  146. <td>Table cell</td>
  147. <td>Table cell</td>
  148. <td>Table cell</td>
  149. <td>Table cell</td>
  150. <td>Table cell</td>
  151. <td>Table cell</td>
  152. </tr>
  153. <tr style="display: none;">
  154. <td>5</td>
  155. <td>Table cell</td>
  156. <td>Table cell</td>
  157. <td>Table cell</td>
  158. <td>Table cell</td>
  159. <td>Table cell</td>
  160. <td>Table cell</td>
  161. </tr>
  162. <tr style="display: none;">
  163. <td>6</td>
  164. <td>Table cell</td>
  165. <td>Table cell</td>
  166. <td>Table cell</td>
  167. <td>Table cell</td>
  168. <td>Table cell</td>
  169. <td>Table cell</td>
  170. </tr>
  171. <tr style="display: none;">
  172. <td>7</td>
  173. <td>Table cell</td>
  174. <td>Table cell</td>
  175. <td>Table cell</td>
  176. <td>Table cell</td>
  177. <td>Table cell</td>
  178. <td>Table cell</td>
  179. </tr>
  180. <tr style="display: none;">
  181. <td>8</td>
  182. <td>Table cell</td>
  183. <td>Table cell</td>
  184. <td>Table cell</td>
  185. <td>Table cell</td>
  186. <td>Table cell</td>
  187. <td>Table cell</td>
  188. </tr>
  189. <tr style="display: none;">
  190. <td>9</td>
  191. <td>Table cell</td>
  192. <td>Table cell</td>
  193. <td>Table cell</td>
  194. <td>Table cell</td>
  195. <td>Table cell</td>
  196. <td>Table cell</td>
  197. </tr>
  198. <tr style="display: none;">
  199. <td>10</td>
  200. <td>Table cell</td>
  201. <td>Table cell</td>
  202. <td>Table cell</td>
  203. <td>Table cell</td>
  204. <td>Table cell</td>
  205. <td>Table cell</td>
  206. </tr>
  207. </tbody>
  208. </table>
  209. </div>
  210. <div class="col-md-12 text-center">
  211. <ul class="pagination pagination-lg pager" id="myPager">
  212. <!--
  213. <li>
  214. <a href="#" class="prev_link" style="display: none;">«</a>
  215. </li>
  216. <li class="active">
  217. <a href="#" class="page_link active">1</a>
  218. </li>
  219. <li>
  220. <a href="#" class="page_link">2</a>
  221. </li>
  222. <li>
  223. <a href="#" class="page_link">3</a>
  224. </li>
  225. <li>
  226. <a href="#" class="next_link">»</a>
  227. </li>
  228. -->
  229. </ul>
  230. </div>
  231. </div>
  232. </div>
  233. </body>
  234. </html>