Dashboard sipadu mbip
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.

dataTables.conditionalPaging.js 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /**
  2. * @summary ConditionalPaging
  3. * @description Hide paging controls when the amount of pages is <= 1
  4. * @version 1.0.0
  5. * @file dataTables.conditionalPaging.js
  6. * @author Matthew Hasbach (https://github.com/mjhasbach)
  7. * @contact hasbach.git@gmail.com
  8. * @copyright Copyright 2015 Matthew Hasbach
  9. *
  10. * License MIT - http://datatables.net/license/mit
  11. *
  12. * This feature plugin for DataTables hides paging controls when the amount
  13. * of pages is <= 1. The controls can either appear / disappear or fade in / out
  14. *
  15. * @example
  16. * $('#myTable').DataTable({
  17. * conditionalPaging: true
  18. * });
  19. *
  20. * @example
  21. * $('#myTable').DataTable({
  22. * conditionalPaging: {
  23. * style: 'fade',
  24. * speed: 500 // optional
  25. * }
  26. * });
  27. */
  28. (function(window, document, $) {
  29. $(document).on('init.dt', function(e, dtSettings) {
  30. if ( e.namespace !== 'dt' ) {
  31. return;
  32. }
  33. var options = dtSettings.oInit.conditionalPaging;
  34. if ($.isPlainObject(options) || options === true) {
  35. var config = $.isPlainObject(options) ? options : {},
  36. api = new $.fn.dataTable.Api(dtSettings),
  37. speed = 'slow',
  38. conditionalPaging = function(e) {
  39. var $paging = $(api.table().container()).find('div.dataTables_paginate'),
  40. pages = api.page.info().pages;
  41. if (e instanceof $.Event) {
  42. if (pages <= 1) {
  43. if (config.style === 'fade') {
  44. $paging.stop().fadeTo(speed, 0);
  45. }
  46. else {
  47. $paging.css('visibility', 'hidden');
  48. }
  49. }
  50. else {
  51. if (config.style === 'fade') {
  52. $paging.stop().fadeTo(speed, 1);
  53. }
  54. else {
  55. $paging.css('visibility', '');
  56. }
  57. }
  58. }
  59. else if (pages <= 1) {
  60. if (config.style === 'fade') {
  61. $paging.css('opacity', 0);
  62. }
  63. else {
  64. $paging.css('visibility', 'hidden');
  65. }
  66. }
  67. };
  68. if ($.isNumeric(config.speed) || $.type(config.speed) === 'string') {
  69. speed = config.speed;
  70. }
  71. conditionalPaging();
  72. api.on('draw.dt', conditionalPaging);
  73. }
  74. });
  75. })(window, document, jQuery);