invoice_archive.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* ------------------------------------------------------------------------------
  2. *
  3. * # Invoice archive
  4. *
  5. * Demo JS code for invoice_archive.html page
  6. *
  7. * ---------------------------------------------------------------------------- */
  8. // Setup module
  9. // ------------------------------
  10. var InvoiceArchive = function() {
  11. //
  12. // Setup module components
  13. //
  14. // Datatable
  15. var _componentDatatable = function() {
  16. if (!$().DataTable) {
  17. console.warn('Warning - datatables.min.js is not loaded.');
  18. return;
  19. }
  20. // Initialize
  21. $('.invoice-archive').DataTable({
  22. autoWidth: false,
  23. columnDefs: [
  24. {
  25. width: 30,
  26. targets: 0
  27. },
  28. {
  29. visible: false,
  30. targets: 1
  31. },
  32. {
  33. orderable: false,
  34. width: 120,
  35. targets: 7
  36. },
  37. {
  38. width: '15%',
  39. targets: [4, 5]
  40. },
  41. {
  42. width: '15%',
  43. targets: 6
  44. },
  45. {
  46. width: '15%',
  47. targets: 3
  48. }
  49. ],
  50. order: [[ 0, 'desc' ]],
  51. dom: '<"datatable-header"fl><"datatable-scroll-lg"t><"datatable-footer"ip>',
  52. language: {
  53. search: '<span>Filter:</span> _INPUT_',
  54. searchPlaceholder: 'Type to filter...',
  55. lengthMenu: '<span>Show:</span> _MENU_',
  56. paginate: { 'first': 'First', 'last': 'Last', 'next': $('html').attr('dir') == 'rtl' ? '&larr;' : '&rarr;', 'previous': $('html').attr('dir') == 'rtl' ? '&rarr;' : '&larr;' }
  57. },
  58. lengthMenu: [ 25, 50, 75, 100 ],
  59. displayLength: 25,
  60. drawCallback: function ( settings ) {
  61. var api = this.api();
  62. var rows = api.rows( {page:'current'} ).nodes();
  63. var last=null;
  64. api.column(1, {page:'current'} ).data().each( function ( group, i ) {
  65. if ( last !== group ) {
  66. $(rows).eq( i ).before(
  67. '<tr class="table-active table-border-double"><td colspan="8" class="font-weight-semibold">'+group+'</td></tr>'
  68. );
  69. last = group;
  70. }
  71. });
  72. // Initializw Select2
  73. if (!$().select2) {
  74. console.warn('Warning - select2.min.js is not loaded.');
  75. return;
  76. }
  77. $('.form-control-select2').select2({
  78. width: 150,
  79. minimumResultsForSearch: Infinity
  80. });
  81. }
  82. });
  83. };
  84. // Select2 for length menu styling
  85. var _componentSelect2 = function() {
  86. if (!$().select2) {
  87. console.warn('Warning - select2.min.js is not loaded.');
  88. return;
  89. }
  90. // Initialize
  91. $('.dataTables_length select').select2({
  92. minimumResultsForSearch: Infinity,
  93. dropdownAutoWidth: true,
  94. width: 'auto'
  95. });
  96. };
  97. //
  98. // Return objects assigned to module
  99. //
  100. return {
  101. init: function() {
  102. _componentDatatable();
  103. _componentSelect2();
  104. }
  105. }
  106. }();
  107. // Initialize module
  108. // ------------------------------
  109. document.addEventListener('DOMContentLoaded', function() {
  110. InvoiceArchive.init();
  111. });