tablelist.tpl 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <script type="text/javascript" charset="utf8" src="{$WEB_ROOT}/templates/{$template}/assets/js/plugins/datatables/jquery.dataTables.min.js"></script>
  2. <script type="text/javascript" charset="utf8" src="{$WEB_ROOT}/templates/{$template}/assets/js/plugins/datatables/dataTables.responsive.js"></script>
  3. <script type="text/javascript" charset="utf8" src="{$WEB_ROOT}/templates/{$template}/assets/js/plugins/datatables/dataTables.bootstrap4.min.js"></script>
  4. {if isset($filterColumn) && $filterColumn}
  5. <script>
  6. if (typeof(buildFilterRegex) !== "function") {
  7. function buildFilterRegex(filterValue) {
  8. if (filterValue.indexOf('&') === -1) {
  9. return '[~>]\\s*' + jQuery.fn.dataTable.util.escapeRegex(filterValue) + '\\s*[<~]';
  10. } else {
  11. var tempDiv = document.createElement('div');
  12. tempDiv.innerHTML = filterValue;
  13. return '\\s*' + jQuery.fn.dataTable.util.escapeRegex(tempDiv.innerText) + '\\s*';
  14. }
  15. }
  16. }
  17. jQuery(document).ready(function () {ldelim}
  18. jQuery(".view-filter-btns .dropdown-menu a").click(function(e) {ldelim}
  19. var filterValue = jQuery(this).find("span").data('value');
  20. var filterText = jQuery(this).find("span").html().trim();
  21. var dataTable = jQuery('#table{$tableName}').DataTable();
  22. var filterValueRegex;
  23. $(this).closest('.dropdown-menu').find('.active').removeClass('active');
  24. $(this).parent().addClass('active');
  25. $(this).closest('.view-filter-btns').find('.dropdown-toggle span').text(filterText);
  26. if (filterValue == "all") {ldelim}
  27. dataTable.column({$filterColumn}).search('').draw();
  28. {rdelim} else {ldelim}
  29. filterValueRegex = buildFilterRegex(filterValue);
  30. dataTable.column({$filterColumn})
  31. .search(filterValueRegex, true, false, false)
  32. .draw();
  33. {rdelim}
  34. // Prevent jumping to the top of the page
  35. // when no matching tag is found.
  36. e.preventDefault();
  37. {rdelim});
  38. {rdelim});
  39. </script>
  40. {/if}
  41. <script>
  42. var alreadyReady = false; // The ready function is being called twice on page load.
  43. jQuery(document).ready( function () {ldelim}
  44. var responsiveHelper = undefined;
  45. {ldelim}var breakpointDefinition = {
  46. tablet: 1024,
  47. phone : 480
  48. };{rdelim}
  49. var tableElement = jQuery("#table{$tableName}");
  50. tableElement.dataTable ({ldelim}
  51. "dom": '<"listtable"fit>pl',{if isset($noPagination) && $noPagination}
  52. "paging": false,{/if}{if isset($noInfo) && $noInfo}
  53. "info": false,{/if}{if isset($noSearch) && $noSearch}
  54. "filter": false,{/if}{if isset($noOrdering) && $noOrdering}
  55. "ordering": false,{/if}
  56. "responsive": true,
  57. "autoWidth": false,
  58. "oLanguage": {ldelim}
  59. "sEmptyTable": "{$LANG.norecordsfound}",
  60. "sInfo": "{$LANG.tableshowing}",
  61. "sInfoEmpty": "{$LANG.tableempty}",
  62. "sInfoFiltered": "{$LANG.tablefiltered}",
  63. "sInfoPostFix": "",
  64. "sInfoThousands": ",",
  65. "sLengthMenu": "{$LANG.tablelength}",
  66. "sLoadingRecords": "{$LANG.tableloading}",
  67. "sProcessing": "{$LANG.tableprocessing}",
  68. "sSearch": "",
  69. "sZeroRecords": "{$LANG.norecordsfound}",
  70. "oPaginate": {ldelim}
  71. "sFirst": "&laquo;",
  72. "sLast": "&raquo;",
  73. "sNext": "&rsaquo;",
  74. "sPrevious": "&lsaquo;"
  75. {rdelim}
  76. {rdelim},
  77. "pageLength": 10,
  78. "order": [
  79. [ {if isset($startOrderCol) && $startOrderCol}{$startOrderCol}{else}0{/if}, "asc" ]
  80. ],
  81. "lengthMenu": [
  82. [10, 25, 50, -1],
  83. [10, 25, 50, "{$LANG.tableviewall}"]
  84. ],
  85. "aoColumnDefs": [
  86. {ldelim}
  87. "bSortable": false,
  88. "aTargets": [ {if isset($noSortColumns) && $noSortColumns !== ''}{$noSortColumns}{/if} ]
  89. {rdelim},
  90. {ldelim}
  91. "sType": "string",
  92. "aTargets": [ {if isset($filterColumn) && $filterColumn}{$filterColumn}{/if} ]
  93. {rdelim}
  94. ],
  95. preDrawCallback: function () {
  96. // Initialize the responsive datatables helper once.
  97. if (!responsiveHelper) {
  98. responsiveHelper = new ResponsiveDatatablesHelper(tableElement, breakpointDefinition);
  99. }
  100. },
  101. rowCallback : function (nRow) {
  102. responsiveHelper.createExpandIcon(nRow);
  103. },
  104. drawCallback : function (oSettings) {
  105. responsiveHelper.respond();
  106. },
  107. "stateSave": true
  108. {rdelim});
  109. {if isset($filterColumn) && $filterColumn}
  110. // highlight remembered filter on page re-load
  111. var table = jQuery('#table{$tableName}').DataTable();
  112. var rememberedFilterTerm = table.state().columns[{$filterColumn}].search.search;
  113. if (rememberedFilterTerm && !alreadyReady) {
  114. // This should only run on the first "ready" event.
  115. jQuery(".view-filter-btns a span").each(function(index) {
  116. if (buildFilterRegex(jQuery(this).text().trim()) == rememberedFilterTerm) {
  117. $(this).closest('li').addClass('active');
  118. $(this).closest('.view-filter-btns').find('.dropdown-toggle span').text(jQuery(this).text());
  119. }
  120. });
  121. }
  122. {/if}
  123. alreadyReady = true;
  124. if (jQuery('#table-search').length > 0 && $('.dataTables_filter').length > 0){
  125. var searchTableVal = $('.dataTables_filter input').val();
  126. jQuery('#table-search').val(searchTableVal);
  127. var searchVal = $('#table-search').val();
  128. table.search(searchVal, true).draw();
  129. }
  130. jQuery('#table-search').on('keyup', function () {
  131. table.search(this.value, true).draw();
  132. });
  133. {rdelim});
  134. </script>