Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

100 строки
4.0 KiB

  1. //http://datatables.net/plug-ins/pagination#bootstrap
  2. $.extend( true, $.fn.dataTable.defaults, {
  3. "sDom": "<'row'<'col-sm-6'l><'col-sm-6'f>r>t<'row'<'col-sm-6'i><'col-sm-6'p>>",
  4. "sPaginationType": "bootstrap",
  5. "oLanguage": {
  6. "sLengthMenu": "Display _MENU_ records"
  7. }
  8. } );
  9. /* API method to get paging information */
  10. $.fn.dataTableExt.oApi.fnPagingInfo = function ( oSettings )
  11. {
  12. return {
  13. "iStart": oSettings._iDisplayStart,
  14. "iEnd": oSettings.fnDisplayEnd(),
  15. "iLength": oSettings._iDisplayLength,
  16. "iTotal": oSettings.fnRecordsTotal(),
  17. "iFilteredTotal": oSettings.fnRecordsDisplay(),
  18. "iPage": Math.ceil( oSettings._iDisplayStart / oSettings._iDisplayLength ),
  19. "iTotalPages": Math.ceil( oSettings.fnRecordsDisplay() / oSettings._iDisplayLength )
  20. };
  21. }
  22. /* Bootstrap style pagination control */
  23. $.extend( $.fn.dataTableExt.oPagination, {
  24. "bootstrap": {
  25. "fnInit": function( oSettings, nPaging, fnDraw ) {
  26. var oLang = oSettings.oLanguage.oPaginate;
  27. var fnClickHandler = function ( e ) {
  28. e.preventDefault();
  29. if ( oSettings.oApi._fnPageChange(oSettings, e.data.action) ) {
  30. fnDraw( oSettings );
  31. }
  32. };
  33. $(nPaging).append(
  34. '<ul class="pagination">'+
  35. '<li class="prev disabled"><a href="#"><i class="icon-double-angle-left"></i></a></li>'+
  36. '<li class="next disabled"><a href="#"><i class="icon-double-angle-right"></i></a></li>'+
  37. '</ul>'
  38. );
  39. var els = $('a', nPaging);
  40. $(els[0]).bind( 'click.DT', { action: "previous" }, fnClickHandler );
  41. $(els[1]).bind( 'click.DT', { action: "next" }, fnClickHandler );
  42. },
  43. "fnUpdate": function ( oSettings, fnDraw ) {
  44. var iListLength = 5;
  45. var oPaging = oSettings.oInstance.fnPagingInfo();
  46. var an = oSettings.aanFeatures.p;
  47. var i, j, sClass, iStart, iEnd, iHalf=Math.floor(iListLength/2);
  48. if ( oPaging.iTotalPages < iListLength) {
  49. iStart = 1;
  50. iEnd = oPaging.iTotalPages;
  51. }
  52. else if ( oPaging.iPage <= iHalf ) {
  53. iStart = 1;
  54. iEnd = iListLength;
  55. } else if ( oPaging.iPage >= (oPaging.iTotalPages-iHalf) ) {
  56. iStart = oPaging.iTotalPages - iListLength + 1;
  57. iEnd = oPaging.iTotalPages;
  58. } else {
  59. iStart = oPaging.iPage - iHalf + 1;
  60. iEnd = iStart + iListLength - 1;
  61. }
  62. for ( i=0, iLen=an.length ; i<iLen ; i++ ) {
  63. // Remove the middle elements
  64. $('li:gt(0)', an[i]).filter(':not(:last)').remove();
  65. // Add the new list items and their event handlers
  66. for ( j=iStart ; j<=iEnd ; j++ ) {
  67. sClass = (j==oPaging.iPage+1) ? 'class="active"' : '';
  68. $('<li '+sClass+'><a href="#">'+j+'</a></li>')
  69. .insertBefore( $('li:last', an[i])[0] )
  70. .bind('click', function (e) {
  71. e.preventDefault();
  72. oSettings._iDisplayStart = (parseInt($('a', this).text(),10)-1) * oPaging.iLength;
  73. fnDraw( oSettings );
  74. } );
  75. }
  76. // Add / remove disabled classes from the static elements
  77. if ( oPaging.iPage === 0 ) {
  78. $('li:first', an[i]).addClass('disabled');
  79. } else {
  80. $('li:first', an[i]).removeClass('disabled');
  81. }
  82. if ( oPaging.iPage === oPaging.iTotalPages-1 || oPaging.iTotalPages === 0 ) {
  83. $('li:last', an[i]).addClass('disabled');
  84. } else {
  85. $('li:last', an[i]).removeClass('disabled');
  86. }
  87. }
  88. }
  89. }
  90. } );