汇联通执法队后台管理系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

jquery.dataTables.bootstrap.js 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /* Set the defaults for DataTables initialisation */
  2. $.extend( true, $.fn.dataTable.defaults, {
  3. "sDom":
  4. "<'row'<'col-xs-6'l><'col-xs-6'f>r>"+
  5. "t"+
  6. "<'row'<'col-xs-6'i><'col-xs-6'p>>",
  7. "sPaginationType": "bootstrap",
  8. "oLanguage": {
  9. "sLengthMenu": "Display _MENU_ records"
  10. }
  11. } );
  12. /* Default class modification */
  13. $.extend( $.fn.dataTableExt.oStdClasses, {
  14. "sWrapper": "dataTables_wrapper form-inline",
  15. "sFilterInput": "form-control input-sm",
  16. "sLengthSelect": "form-control input-sm"
  17. } );
  18. // In 1.10 we use the pagination renderers to draw the Bootstrap paging,
  19. // rather than custom plug-in
  20. if ( $.fn.dataTable.Api ) {
  21. $.fn.dataTable.defaults.renderer = 'bootstrap';
  22. $.fn.dataTable.ext.renderer.pageButton.bootstrap = function ( settings, host, idx, buttons, page, pages ) {
  23. var api = new $.fn.dataTable.Api( settings );
  24. var classes = settings.oClasses;
  25. var lang = settings.oLanguage.oPaginate;
  26. var btnDisplay, btnClass;
  27. var attach = function( container, buttons ) {
  28. var i, ien, node, button;
  29. var clickHandler = function ( e ) {
  30. e.preventDefault();
  31. if ( e.data.action !== 'ellipsis' ) {
  32. api.page( e.data.action ).draw( false );
  33. }
  34. };
  35. for ( i=0, ien=buttons.length ; i<ien ; i++ ) {
  36. button = buttons[i];
  37. if ( $.isArray( button ) ) {
  38. attach( container, button );
  39. }
  40. else {
  41. btnDisplay = '';
  42. btnClass = '';
  43. switch ( button ) {
  44. case 'ellipsis':
  45. btnDisplay = '&hellip;';
  46. btnClass = 'disabled';
  47. break;
  48. case 'first':
  49. btnDisplay = lang.sFirst;
  50. btnClass = button + (page > 0 ?
  51. '' : ' disabled');
  52. break;
  53. case 'previous':
  54. btnDisplay = lang.sPrevious;
  55. btnClass = button + (page > 0 ?
  56. '' : ' disabled');
  57. break;
  58. case 'next':
  59. btnDisplay = lang.sNext;
  60. btnClass = button + (page < pages-1 ?
  61. '' : ' disabled');
  62. break;
  63. case 'last':
  64. btnDisplay = lang.sLast;
  65. btnClass = button + (page < pages-1 ?
  66. '' : ' disabled');
  67. break;
  68. default:
  69. btnDisplay = button + 1;
  70. btnClass = page === button ?
  71. 'active' : '';
  72. break;
  73. }
  74. if ( btnDisplay ) {
  75. node = $('<li>', {
  76. 'class': classes.sPageButton+' '+btnClass,
  77. 'aria-controls': settings.sTableId,
  78. 'tabindex': settings.iTabIndex,
  79. 'id': idx === 0 && typeof button === 'string' ?
  80. settings.sTableId +'_'+ button :
  81. null
  82. } )
  83. .append( $('<a>', {
  84. 'href': '#'
  85. } )
  86. .html( btnDisplay )
  87. )
  88. .appendTo( container );
  89. settings.oApi._fnBindAction(
  90. node, {action: button}, clickHandler
  91. );
  92. }
  93. }
  94. }
  95. };
  96. attach(
  97. $(host).empty().html('<ul class="pagination"/>').children('ul'),
  98. buttons
  99. );
  100. }
  101. }
  102. else {
  103. // Integration for 1.9-
  104. $.fn.dataTable.defaults.sPaginationType = 'bootstrap';
  105. /* API method to get paging information */
  106. $.fn.dataTableExt.oApi.fnPagingInfo = function ( oSettings )
  107. {
  108. return {
  109. "iStart": oSettings._iDisplayStart,
  110. "iEnd": oSettings.fnDisplayEnd(),
  111. "iLength": oSettings._iDisplayLength,
  112. "iTotal": oSettings.fnRecordsTotal(),
  113. "iFilteredTotal": oSettings.fnRecordsDisplay(),
  114. "iPage": oSettings._iDisplayLength === -1 ?
  115. 0 : Math.ceil( oSettings._iDisplayStart / oSettings._iDisplayLength ),
  116. "iTotalPages": oSettings._iDisplayLength === -1 ?
  117. 0 : Math.ceil( oSettings.fnRecordsDisplay() / oSettings._iDisplayLength )
  118. };
  119. };
  120. /* Bootstrap style pagination control */
  121. $.extend( $.fn.dataTableExt.oPagination, {
  122. "bootstrap": {
  123. "fnInit": function( oSettings, nPaging, fnDraw ) {
  124. var oLang = oSettings.oLanguage.oPaginate;
  125. var fnClickHandler = function ( e ) {
  126. e.preventDefault();
  127. if ( oSettings.oApi._fnPageChange(oSettings, e.data.action) ) {
  128. fnDraw( oSettings );
  129. }
  130. };
  131. //Pagination Buttons
  132. $(nPaging).append(
  133. '<ul class="pagination">'+
  134. '<li class="prev disabled"><a href="#"><i class="fa fa-angle-double-left"></i></a></li>'+//first
  135. '<li class="prev disabled"><a href="#"><i class="fa fa-angle-left"></i></a></li>'+//next
  136. '<li class="next disabled"><a href="#"><i class="fa fa-angle-right"></i></a></li>'+//prev
  137. '<li class="next disabled"><a href="#"><i class="fa fa-angle-double-right"></i></a></li>'+//last
  138. '</ul>'
  139. );
  140. var els = $('a', nPaging);
  141. $(els[0]).bind( 'click.DT', { action: "first" }, fnClickHandler );//first
  142. $(els[1]).bind( 'click.DT', { action: "previous" }, fnClickHandler );//next
  143. $(els[2]).bind( 'click.DT', { action: "next" }, fnClickHandler );//prev
  144. $(els[3]).bind( 'click.DT', { action: "last" }, fnClickHandler );//last
  145. //if you don't want the "first & last" buttons, you can remove the relevant HTML line and event handlers
  146. },
  147. "fnUpdate": function ( oSettings, fnDraw ) {
  148. var iListLength = 5;
  149. var oPaging = oSettings.oInstance.fnPagingInfo();
  150. var an = oSettings.aanFeatures.p;
  151. var i, ien, j, sClass, iStart, iEnd, iHalf=Math.floor(iListLength/2);
  152. if ( oPaging.iTotalPages < iListLength) {
  153. iStart = 1;
  154. iEnd = oPaging.iTotalPages;
  155. }
  156. else if ( oPaging.iPage <= iHalf ) {
  157. iStart = 1;
  158. iEnd = iListLength;
  159. } else if ( oPaging.iPage >= (oPaging.iTotalPages-iHalf) ) {
  160. iStart = oPaging.iTotalPages - iListLength + 1;
  161. iEnd = oPaging.iTotalPages;
  162. } else {
  163. iStart = oPaging.iPage - iHalf + 1;
  164. iEnd = iStart + iListLength - 1;
  165. }
  166. for ( i=0, ien=an.length ; i<ien ; i++ ) {
  167. // Remove the middle elements
  168. $('li:gt(0)', an[i]).filter(':not(.next,.prev)').remove();//ACE
  169. // Add the new list items and their event handlers
  170. for ( j=iStart ; j<=iEnd ; j++ ) {
  171. sClass = (j==oPaging.iPage+1) ? 'class="active"' : '';
  172. $('<li '+sClass+'><a href="#">'+j+'</a></li>')
  173. .insertBefore( $('li.next:eq(0)', an[i])[0] )//ACE
  174. .bind('click', function (e) {
  175. e.preventDefault();
  176. oSettings._iDisplayStart = (parseInt($('a', this).text(),10)-1) * oPaging.iLength;
  177. fnDraw( oSettings );
  178. } );
  179. }
  180. // Add / remove disabled classes from the static elements
  181. //ACE
  182. if ( oPaging.iPage === 0 ) {
  183. $('li.prev', an[i]).addClass('disabled');
  184. } else {
  185. $('li.prev', an[i]).removeClass('disabled');
  186. }
  187. if ( oPaging.iPage === oPaging.iTotalPages-1 || oPaging.iTotalPages === 0 ) {
  188. $('li.next', an[i]).addClass('disabled');
  189. } else {
  190. $('li.next', an[i]).removeClass('disabled');
  191. }
  192. }
  193. }
  194. }
  195. } );
  196. }
  197. /*
  198. * TableTools Bootstrap compatibility
  199. * Required TableTools 2.1+
  200. */
  201. if ( $.fn.DataTable.TableTools ) {
  202. // Set the classes that TableTools uses to something suitable for Bootstrap
  203. $.extend( true, $.fn.DataTable.TableTools.classes, {
  204. "container": "DTTT btn-group",
  205. "buttons": {
  206. "normal": "btn btn-default",
  207. "disabled": "disabled"
  208. },
  209. "collection": {
  210. "container": "DTTT_dropdown dropdown-menu",
  211. "buttons": {
  212. "normal": "",
  213. "disabled": "disabled"
  214. }
  215. },
  216. "print": {
  217. "info": "DTTT_print_info modal"
  218. },
  219. "select": {
  220. "row": "active"
  221. }
  222. } );
  223. // Have the collection use a bootstrap compatible dropdown
  224. $.extend( true, $.fn.DataTable.TableTools.DEFAULTS.oTags, {
  225. "collection": {
  226. "container": "ul",
  227. "button": "li",
  228. "liner": "a"
  229. }
  230. } );
  231. }