datatables_style.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /* Default class modification */
  2. $.extend($.fn.dataTableExt.oStdClasses, {
  3. "sSortAsc" : "header headerSortDown",
  4. "sSortDesc" : "header headerSortUp",
  5. "sSortable" : "header"
  6. });
  7. /* API method to get paging information */
  8. $.fn.dataTableExt.oApi.fnPagingInfo = function(oSettings) {
  9. return {
  10. "iStart" : oSettings._iDisplayStart,
  11. "iEnd" : oSettings.fnDisplayEnd(),
  12. "iLength" : oSettings._iDisplayLength,
  13. "iTotal" : oSettings.fnRecordsTotal(),
  14. "iFilteredTotal" : oSettings.fnRecordsDisplay(),
  15. "iPage" : Math.ceil(oSettings._iDisplayStart
  16. / oSettings._iDisplayLength),
  17. "iTotalPages" : Math.ceil(oSettings.fnRecordsDisplay()
  18. / oSettings._iDisplayLength)
  19. };
  20. };
  21. /* Bootstrap style pagination control */
  22. $.extend(
  23. $.fn.dataTableExt.oPagination,
  24. {
  25. "bootstrap" : {
  26. "fnInit" : function(oSettings, nPaging, fnDraw) {
  27. var oLang = oSettings.oLanguage.oPaginate;
  28. var fnClickHandler = function(e) {
  29. e.preventDefault();
  30. if (oSettings.oApi._fnPageChange(oSettings,
  31. e.data.action)) {
  32. fnDraw(oSettings);
  33. }
  34. };
  35. $(nPaging)
  36. .addClass('pagination')
  37. .append(
  38. '<ul>'
  39. + '<li class="prev disabled"><a href="#">&larr; '
  40. + oLang.sPrevious
  41. + '</a></li>'
  42. + '<li class="next disabled"><a href="#">'
  43. + oLang.sNext
  44. + ' &rarr; </a></li>'
  45. + '</ul>');
  46. var els = $('a', nPaging);
  47. $(els[0]).bind('click.DT', {
  48. action : "previous"
  49. }, fnClickHandler);
  50. $(els[1]).bind('click.DT', {
  51. action : "next"
  52. }, fnClickHandler);
  53. },
  54. "fnUpdate" : function(oSettings, fnDraw) {
  55. var iListLength = 5;
  56. var oPaging = oSettings.oInstance.fnPagingInfo();
  57. var an = oSettings.aanFeatures.p;
  58. var i, j, sClass, iStart, iEnd, iHalf = Math
  59. .floor(iListLength / 2);
  60. if (oPaging.iTotalPages < iListLength) {
  61. iStart = 1;
  62. iEnd = oPaging.iTotalPages;
  63. } else if (oPaging.iPage <= iHalf) {
  64. iStart = 1;
  65. iEnd = iListLength;
  66. } else if (oPaging.iPage >= (oPaging.iTotalPages - iHalf)) {
  67. iStart = oPaging.iTotalPages - iListLength + 1;
  68. iEnd = oPaging.iTotalPages;
  69. } else {
  70. iStart = oPaging.iPage - iHalf + 1;
  71. iEnd = iStart + iListLength - 1;
  72. }
  73. for (i = 0, iLen = an.length; i < iLen; i++) {
  74. // Remove the middle elements
  75. $('li:gt(0)', an[i]).filter(':not(:last)')
  76. .remove();
  77. // Add the new list items and their event
  78. // handlers
  79. for (j = iStart; j <= iEnd; j++) {
  80. sClass = (j == oPaging.iPage + 1) ? 'class="active"'
  81. : '';
  82. $(
  83. '<li ' + sClass + '><a href="#">'
  84. + j + '</a></li>')
  85. .insertBefore(
  86. $('li:last', an[i])[0])
  87. .bind(
  88. 'click',
  89. function(e) {
  90. e.preventDefault();
  91. oSettings._iDisplayStart = (parseInt(
  92. $('a', this)
  93. .text(),
  94. 10) - 1)
  95. * oPaging.iLength;
  96. fnDraw(oSettings);
  97. });
  98. }
  99. // Add / remove disabled classes from the static
  100. // elements
  101. if (oPaging.iPage === 0) {
  102. $('li:first', an[i]).addClass('disabled');
  103. } else {
  104. $('li:first', an[i])
  105. .removeClass('disabled');
  106. }
  107. if (oPaging.iPage === oPaging.iTotalPages - 1
  108. || oPaging.iTotalPages === 0) {
  109. $('li:last', an[i]).addClass('disabled');
  110. } else {
  111. $('li:last', an[i]).removeClass('disabled');
  112. }
  113. }
  114. }
  115. }
  116. });