datatable.html.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php if($extView = $this->getExtViewFile(__FILE__)){include $extView; return helper::cd();}?>
  2. <?php js::import($jsRoot . 'datatable/min.js'); ?>
  3. <?php css::import($jsRoot . 'datatable/min.css'); ?>
  4. <?php if(!empty($lang->datatable)):?>
  5. <style>
  6. .datatable {margin-bottom: 0;}
  7. .datatable .table>tbody>tr>td, .datatable .table>thead>tr>th {line-height: 29px; padding-top: 2px; padding-bottom: 2px; height: 36px; vertical-align: middle; white-space: nowrap;}
  8. .datatable .table>tbody>tr.hover {box-shadow: none!important;}
  9. .datatable .flexarea .table-children,
  10. .datatable .fixed-left .table-children {border-right: none;}
  11. .datatable .flexarea .table-children,
  12. .datatable .fixed-right .table-children {border-left: none;}
  13. .datatable tr.hover td.c-actions .more {display: block; background-color: #ebf2f9}
  14. .datatable .fixed-left .table,
  15. .datatable .flexarea .table,
  16. .datatable .flexarea tbody > tr.checked,
  17. .datatable .fixed-left tbody > tr.checked {border-top-right-radius: 0; border-bottom-right-radius: 0;}
  18. .datatable .flexarea tbody > tr.checked,
  19. .datatable .fixed-right .table,
  20. .datatable .flexarea .table,
  21. .datatable .fixed-right tbody > tr.checked {border-top-left-radius: 0; border-bottom-left-radius: 0;}
  22. .datatable .flexarea tbody>tr.checked>td:first-child:before,
  23. .datatable .fixed-right tbody>tr.checked>td:first-child:before {display: none}
  24. .datatable>.scroll-wrapper {z-index: 10;}
  25. .has-fixed-footer .scroll-wrapper {bottom: 49px; position: fixed;}
  26. .has-fixed-footer .scroll-wrapper .scroll-slide.scroll-pos-out{height:8px;bottom: -8px;}
  27. .has-fixed-footer .scroll-wrapper .scroll-slide.scroll-pos-out .bar{height:8px;}
  28. .datatable .flexarea thead>tr>th:first-child,
  29. .datatable .flexarea tbody>tr>td:first-child,
  30. .datatable .fixed-right thead>tr>th:first-child,
  31. .datatable .fixed-right tbody>tr>td {padding-left: 5px!important;}
  32. .datatable .c-actions {white-space: nowrap;}
  33. .datatable.head-fixed {padding-top: 41px;}
  34. .datatable .table>thead>tr>th.col-hover {background: rgba(0,0,0,.07);}
  35. </style>
  36. <script>
  37. <?php $datatableId = $this->moduleName . ucfirst($this->methodName);?>
  38. var datatableOptions =
  39. {
  40. customizable : false,
  41. sortable : false,
  42. scrollPos : 'out',
  43. tableClass : 'tablesorter',
  44. storage : false,
  45. fixCellHeight : false,
  46. selectable : false,
  47. fixedHeader: true,
  48. ready: function()
  49. {
  50. this.$table.addClass('datatable-origin');
  51. if (this.$table.hasClass('has-sort-head'))
  52. {
  53. this.$datatable.find('.table').addClass('has-sort-head');
  54. }
  55. this.$datatable.find('.sparkline').sparkline();
  56. $('.progress-pie').progressPie();
  57. }
  58. };
  59. /**
  60. * Init datatable.
  61. *
  62. * @param int $datatable
  63. * @access public
  64. * @return void
  65. */
  66. function initDatatable($datatable)
  67. {
  68. $datatable = $datatable || $('table.datatable').first();
  69. if(!$datatable.length || $datatable.data('zui.datatable')) return null;
  70. var $datatable = $('table.datatable').first();
  71. var datatableId = $datatable.attr('id');
  72. var dtSetting = $.cookie('datatable.<?php echo $datatableId?>' + '.cols') || {};
  73. if(dtSetting === 'null') dtSetting = {};
  74. if(typeof dtSetting === 'string') dtSetting = $.parseJSON(dtSetting);
  75. $datatable.datatable(datatableOptions);
  76. $datatable.find('thead>tr>th').each(function(idx)
  77. {
  78. var $th = $(this);
  79. idx = $th.data('index') || idx;
  80. var colSetting = dtSetting[idx];
  81. $th.toggleClass('ignore', !!(colSetting && colSetting.ignore));
  82. });
  83. return $datatable;
  84. };
  85. $(document).ready(function()
  86. {
  87. var $datatable = initDatatable();
  88. if($datatable && $datatable.length)
  89. {
  90. $('#main').on('beforeTableReload', '[data-ride="table"]', function()
  91. {
  92. initDatatable($datatable);
  93. });
  94. }
  95. window.saveDatatableConfig = function(name, value, reload, global)
  96. {
  97. if('<?php echo $this->app->user->account?>' == 'guest') return;
  98. var datatableId = '<?php echo $datatableId;?>';
  99. if(typeof value === 'object') value = JSON.stringify(value);
  100. if(typeof global === 'undefined') global = 0;
  101. $.ajax(
  102. {
  103. type: "POST",
  104. dataType: 'json',
  105. data: {target: datatableId, name: name, value: value, global: global},
  106. success:function(e){if(reload) window.location.reload();},
  107. url: '<?php echo $this->createLink('datatable', 'ajaxOldSave')?>'
  108. });
  109. };
  110. var $modal = $('#customDatatable');
  111. var $checkList = $modal.find('.modal-body > .table > tbody');
  112. $checkList.on('click', 'tr', function()
  113. {
  114. var $tr = $(this);
  115. if($tr.hasClass('disabled')) return;
  116. $tr.toggleClass('checked');
  117. });
  118. $(window).on('fixFooter', function(e, isFixed)
  119. {
  120. $('body').toggleClass('has-fixed-footer', isFixed);
  121. });
  122. });
  123. </script>
  124. <?php endif;?>