当前位置:   article > 正文

bootstrap table 冻结列 操作无效_bootstrap fixedcolumns 不生效

bootstrap fixedcolumns 不生效

 

此问题产生的原因 感觉是因为冻结列是在上边又盖了一层表格导致无效。

所以点击事件的解决方法的原理是转移点击事件

bootstrap-table-fixed-columns.js 中修改代码  
本人代码操作列是 使用a标签 

见下图

当然 找a标签的时候可以直接使用fixtb.find('a');无需再去判断
具体判断添加点击事件位置 需要根据自己项目情况酌情修改  
 

  1. (function ($) {
  2. 'use strict';
  3. $.extend($.fn.bootstrapTable.defaults, {
  4. fixedColumns: false,
  5. fixedNumber: 1
  6. });
  7. var BootstrapTable = $.fn.bootstrapTable.Constructor,
  8. _initHeader = BootstrapTable.prototype.initHeader,
  9. _initBody = BootstrapTable.prototype.initBody,
  10. _resetView = BootstrapTable.prototype.resetView;
  11. BootstrapTable.prototype.initFixedColumns = function () {
  12. // debugger
  13. this.$fixedHeader = $([
  14. '<div class="fixed-table-header-columns">',
  15. '<table>',
  16. '<thead></thead>',
  17. '</table>',
  18. '</div>'].join(''));
  19. this.timeoutHeaderColumns_ = 0;
  20. this.$fixedHeader.find('table').attr('class', this.$el.attr('class'));
  21. this.$fixedHeaderColumns = this.$fixedHeader.find('thead');
  22. this.$tableHeader.before(this.$fixedHeader);
  23. this.$fixedBody = $([
  24. '<div class="fixed-table-body-columns">',
  25. '<table>',
  26. '<tbody></tbody>',
  27. '</table>',
  28. '</div>'].join(''));
  29. this.timeoutBodyColumns_ = 0;
  30. this.$fixedBody.find('table').attr('class', this.$el.attr('class'));
  31. this.$fixedBodyColumns = this.$fixedBody.find('tbody');
  32. this.$tableBody.before(this.$fixedBody);
  33. };
  34. BootstrapTable.prototype.initHeader = function () {
  35. _initHeader.apply(this, Array.prototype.slice.apply(arguments));
  36. if (!this.options.fixedColumns) {
  37. return;
  38. }
  39. this.initFixedColumns();
  40. var that = this, $trs = this.$header.find('tr').clone();
  41. $trs.each(function () {
  42. $(this).find('th:gt(' + (that.options.fixedNumber - 1) + ')').remove();
  43. });
  44. this.$fixedHeaderColumns.html('').append($trs);
  45. };
  46. BootstrapTable.prototype.initBody = function () {
  47. _initBody.apply(this, Array.prototype.slice.apply(arguments));
  48. if (!this.options.fixedColumns) {
  49. return;
  50. }
  51. var that = this,
  52. rowspan = 0;
  53. this.$fixedBodyColumns.html('');
  54. this.$body.find('> tr[data-index]').each(function () {
  55. var $tr = $(this).clone(),
  56. $tds = $tr.find('td');
  57. //$tr.html('');这样存在一个兼容性问题,在IE浏览器里面,清空tr,$tds的值也会被清空。
  58. //$tr.html('');
  59. var $newtr = $('<tr></tr>');
  60. $newtr.attr('data-index', $tr.attr('data-index'));
  61. $newtr.attr('data-uniqueid', $tr.attr('data-uniqueid'));
  62. var end = that.options.fixedNumber;
  63. if (rowspan > 0) {
  64. --end;
  65. --rowspan;
  66. }
  67. for (var i = 0; i < end; i++) {
  68. var fixtb=$tds.eq(i).clone();
  69. var bodytd=$(this).find('td').eq(i);
  70. if(fixtb.length>0){
  71. if(fixtb[0].childNodes.length>0){
  72. if(fixtb[0].childNodes[0].tagName=='A'){
  73. var htmldiva=bodytd[0].childNodes;
  74. var fixhtmldiva=fixtb[0].childNodes;
  75. fixhtmldiva.forEach(function (item,key){
  76. $(item).click(function(){
  77. htmldiva[key].click();
  78. })
  79. })
  80. }
  81. }
  82. }
  83. $newtr.append(fixtb);
  84. }
  85. that.$fixedBodyColumns.append($newtr);
  86. if ($tds.eq(0).attr('rowspan')) {
  87. rowspan = $tds.eq(0).attr('rowspan') - 1;
  88. }
  89. });
  90. };
  91. BootstrapTable.prototype.resetView = function () {
  92. _resetView.apply(this, Array.prototype.slice.apply(arguments));
  93. if (!this.options.fixedColumns) {
  94. return;
  95. }
  96. clearTimeout(this.timeoutHeaderColumns_);
  97. this.timeoutHeaderColumns_ = setTimeout($.proxy(this.fitHeaderColumns, this), this.$el.is(':hidden') ? 100 : 0);
  98. clearTimeout(this.timeoutBodyColumns_);
  99. this.timeoutBodyColumns_ = setTimeout($.proxy(this.fitBodyColumns, this), this.$el.is(':hidden') ? 100 : 0);
  100. };
  101. BootstrapTable.prototype.fitHeaderColumns = function () {
  102. var that = this,
  103. visibleFields = this.getVisibleFields(),
  104. headerWidth = 0;
  105. this.$body.find('tr:first-child:not(.no-records-found) > *').each(function (i) {
  106. var $this = $(this),
  107. index = i;
  108. if (i >= that.options.fixedNumber) {
  109. return false;
  110. }
  111. if (that.options.detailView && !that.options.cardView) {
  112. index = i - 1;
  113. }
  114. that.$fixedHeader.find('th[data-field="' + visibleFields[index] + '"]')
  115. .find('.fht-cell').width($this.innerWidth());
  116. headerWidth += $this.outerWidth();
  117. });
  118. this.$fixedHeader.width(headerWidth).show();
  119. };
  120. BootstrapTable.prototype.fitBodyColumns = function () {
  121. var that = this,
  122. top = -(parseInt(this.$el.css('margin-top'))),
  123. // the fixed height should reduce the scorll-x height
  124. height = this.$tableBody.height() - 12;
  125. if (!this.$body.find('> tr[data-index]').length) {
  126. this.$fixedBody.hide();
  127. return;
  128. }
  129. if (!this.options.height) {
  130. top = this.$fixedHeader.height()- 0;
  131. height = height - top;
  132. }
  133. this.$fixedBody.css({
  134. width: this.$fixedHeader.width()+2,
  135. height: height+2,
  136. top: top + 1
  137. }).show();
  138. this.$body.find('> tr').each(function (i) {
  139. that.$fixedBody.find('tr:eq(' + i + ')').height($(this).height() - 0.5);
  140. var thattds = this;
  141. that.$fixedBody.find('tr:eq(' + i + ')').find('td').each(function (j) {
  142. $(this).width($($(thattds).find('td')[j]).width() );
  143. });
  144. /*that.$fixedBody.find('tr:eq(3)').find('td').width($($(thattds).find('td')[3]).width()+1 );*/
  145. });
  146. // events
  147. this.$tableBody.on('scroll', function () {
  148. that.$fixedBody.find('table').css('top', -$(this).scrollTop());
  149. });
  150. this.$body.find('> tr[data-index]').off('hover').hover(function () {
  151. var index = $(this).data('index');
  152. that.$fixedBody.find('tr[data-index="' + index + '"]').addClass('hover');
  153. }, function () {
  154. var index = $(this).data('index');
  155. that.$fixedBody.find('tr[data-index="' + index + '"]').removeClass('hover');
  156. });
  157. this.$fixedBody.find('tr[data-index]').off('hover').hover(function () {
  158. var index = $(this).data('index');
  159. that.$body.find('tr[data-index="' + index + '"]').addClass('hover');
  160. }, function () {
  161. var index = $(this).data('index');
  162. that.$body.find('> tr[data-index="' + index + '"]').removeClass('hover');
  163. });
  164. };
  165. })(jQuery);

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/299207
推荐阅读