<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12
        

      JS組件系列——Bootstrap Table 凍結列功能IE瀏覽器兼容性問題解決方案

      前言:最近項目里面需要用到表格的凍結列功能,所謂“凍結列”,就是某些情況下表格的列比較多,需要固定前面的幾列,后面的列滾動。遺憾的是,bootstrap table里自帶的fixed column功能有一點bug,于是和同事討論該如何解決,于是就有了這篇文章。

      一、起因回顧

      最近項目里面有一個表格需求,該表格列是動態產生的,而且列的數量操作一定值以后就會出現橫向滾動條,滾動的時候需要前面幾列固定。也就是所謂的excel的凍結列功能。該如何實現呢?不用多說,當然是查文檔,于是找到了這篇http://issues.wenzhixin.net.cn/bootstrap-table/index.html#extensions/fixed-columns.html。谷歌瀏覽器效果如下:

      第一列固定

      貌似問題完美解決!可是,事與愿違,很遺憾,上面說了,這是谷歌瀏覽器的效果,沒有問題。我們來看看IE里面

      IE11效果:

      IE10效果:

      很顯然,不管是IE內核版本多少,凍結的列里面的內容都無法顯示。怎么辦?這可為難死寶寶了!

      二、解決方案

      還好有萬能的開源,查看該頁面源代碼發現可以找到凍結列這個js的源碼。

      點擊進入可以看到這個js的所有源碼,找到源碼就好辦了,我們試著改改源碼看是否能解決這個bug。

      我們在bootstrap-table下面的extensions文件夾下面新增加一個文件夾fixed-column

      下面就貼出我們改好的源碼:

      (function ($) {
          'use strict';
      
          $.extend($.fn.bootstrapTable.defaults, {
              fixedColumns: false,
              fixedNumber: 1
          });
      
          var BootstrapTable = $.fn.bootstrapTable.Constructor,
              _initHeader = BootstrapTable.prototype.initHeader,
              _initBody = BootstrapTable.prototype.initBody,
              _resetView = BootstrapTable.prototype.resetView;
      
          BootstrapTable.prototype.initFixedColumns = function () {
              this.$fixedBody = $([
                  '<div class="fixed-table-column" style="position: absolute; background-color: #fff; border-right:1px solid #ddd;">',
                  '<table>',
                  '<thead></thead>',
                  '<tbody></tbody>',
                  '</table>',
                  '</div>'].join(''));
      
              this.timeoutHeaderColumns_ = 0;
              this.timeoutBodyColumns_ = 0;
              this.$fixedBody.find('table').attr('class', this.$el.attr('class'));
              this.$fixedHeaderColumns = this.$fixedBody.find('thead');
              this.$fixedBodyColumns = this.$fixedBody.find('tbody');
              this.$tableBody.before(this.$fixedBody);
          };
      
          BootstrapTable.prototype.initHeader = function () {
              _initHeader.apply(this, Array.prototype.slice.apply(arguments));
      
              if (!this.options.fixedColumns) {
                  return;
              }
      
              this.initFixedColumns();
      
              var $tr = this.$header.find('tr:eq(0)').clone(),
                  $ths = $tr.clone().find('th');
      
              $tr.html('');
              for (var i = 0; i < this.options.fixedNumber; i++) {
                  $tr.append($ths.eq(i).clone());
              }
              this.$fixedHeaderColumns.html('').append($tr);
          };
      
          BootstrapTable.prototype.initBody = function () {
              _initBody.apply(this, Array.prototype.slice.apply(arguments));
      
              if (!this.options.fixedColumns) {
                  return;
              }
      
              var that = this;
      
              this.$fixedBodyColumns.html('');
              this.$body.find('> tr[data-index]').each(function () {
                  var $tr = $(this).clone(),
                      $tds = $tr.clone().find('td');
      
                  $tr.html('');
                  for (var i = 0; i < that.options.fixedNumber; i++) {
                      $tr.append($tds.eq(i).clone());
                  }
                  that.$fixedBodyColumns.append($tr);
              });
          };
      
          BootstrapTable.prototype.resetView = function () {
              _resetView.apply(this, Array.prototype.slice.apply(arguments));
      
              if (!this.options.fixedColumns) {
                  return;
              }
      
              clearTimeout(this.timeoutHeaderColumns_);
              this.timeoutHeaderColumns_ = setTimeout($.proxy(this.fitHeaderColumns, this), this.$el.is(':hidden') ? 100 : 0);
      
              clearTimeout(this.timeoutBodyColumns_);
              this.timeoutBodyColumns_ = setTimeout($.proxy(this.fitBodyColumns, this), this.$el.is(':hidden') ? 100 : 0);
          };
      
          BootstrapTable.prototype.fitHeaderColumns = function () {
              var that = this,
                  visibleFields = this.getVisibleFields(),
                  headerWidth = 0;
      
              this.$body.find('tr:first-child:not(.no-records-found) > *').each(function (i) {
                  var $this = $(this),
                      index = i;
      
                  if (i >= that.options.fixedNumber) {
                      return false;
                  }
      
                  if (that.options.detailView && !that.options.cardView) {
                      index = i - 1;
                  }
      
                  that.$fixedBody.find('thead th[data-field="' + visibleFields[index] + '"]')
                      .find('.fht-cell').width($this.innerWidth() - 1);
                  headerWidth += $this.outerWidth();
              });
              this.$fixedBody.width(headerWidth - 1).show();
          };
      
          BootstrapTable.prototype.fitBodyColumns = function () {
              var that = this,
                  top = -(parseInt(this.$el.css('margin-top')) - 2),
                  height = this.$tableBody.height() - 2;
      
              if (!this.$body.find('> tr[data-index]').length) {
                  this.$fixedBody.hide();
                  return;
              }
      
              this.$body.find('> tr').each(function (i) {
                  that.$fixedBody.find('tbody tr:eq(' + i + ')').height($(this).height() - 1);
              });
      
              //// events
              this.$tableBody.on('scroll', function () {
                  that.$fixedBody.find('table').css('top', -$(this).scrollTop());
              });
              this.$body.find('> tr[data-index]').off('hover').hover(function () {
                  var index = $(this).data('index');
                  that.$fixedBody.find('tr[data-index="' + index + '"]').addClass('hover');
              }, function () {
                  var index = $(this).data('index');
                  that.$fixedBody.find('tr[data-index="' + index + '"]').removeClass('hover');
              });
              this.$fixedBody.find('tr[data-index]').off('hover').hover(function () {
                  var index = $(this).data('index');
                  that.$body.find('tr[data-index="' + index + '"]').addClass('hover');
              }, function () {
                  var index = $(this).data('index');
                  that.$body.find('> tr[data-index="' + index + '"]').removeClass('hover');
              });
          };
      
      })(jQuery);
      bootstrap-table-fixed-columns.js修改后的源碼
              .fixed-table-container thead th .th-inner, .fixed-table-container tbody td .th-inner {
                  line-height: 18px;
              }
      
              .fixed-table-pagination .pagination a {
                  padding: 5px 10px;
              }
      
              .fixed-table-toolbar .bars, .fixed-table-toolbar .search, .fixed-table-toolbar .columns {
                  margin-top: 5px;
                  margin-bottom: 5px;
              }
      bootstrap-table-fixed-columns.css修改后

      主要修改的地方:

      1)源碼里面將thead和tbody分別封裝成了一個單獨的表格,修改后將thead和tbody放到了一個table里面;

      2)依次遍歷凍結的列放入到固定的tbody里面;

      其實也就改了那么幾個地方,就能完美解決IE的bug。我們先來看看效果:

      IE11

      IE10

      IE8

       

      我們再來看看如何使用。

      1、引用js和對應的css

      <script src="~/Content/bootstrap-table/extensions/fixed-column/js/bootstrap-table-fixed-columns.js"></script>
      <link href="~/Content/bootstrap-table/extensions/fixed-column/css/bootstrap-table-fixed-columns.css" rel="stylesheet" />

      2、js調用如下

      加兩個參數fixedColumns和fixedNumber即可,什么意思不用過多解釋,是否凍結列、凍結列的列數。還有一點需要說明的是,這里調用的時候不能指定它的height,如果指定height,表格的凍結顯示會有問題。

      三、總結

      以上就是表格凍結關于IE兼容性問題的解決方案,如果你也正好用到bootstrap table 的列凍結,呵呵,福利來了??傮w上來說,就是在原有擴展js的基礎上面做了一些小小的修改。能用,如果大伙覺得有什么問題,歡迎指出。

      源碼下載

       

      posted @ 2016-01-27 16:18  懶得安分  閱讀(39455)  評論(15)    收藏  舉報
      主站蜘蛛池模板: 亚洲国产精品高清久久久| 色成人亚洲| 日韩精品无码免费专区午夜不卡| 97se亚洲综合在线天天| 丰满少妇熟乱xxxxx视频| 国产一区二区视频啪啪视频 | 高清一区二区三区不卡视频| 国产精品多p对白交换绿帽| 亚洲国产成人精品女人久| 人妻日韩人妻中文字幕| 野外做受三级视频| 国产亚洲综合另类色专区| 国产精品国产主播在线观看| 狠狠亚洲超碰狼人久久| 天天躁夜夜踩很很踩2022| 成人午夜无人区一区二区| 天堂国产一区二区三区四区不卡| 亚洲区一区二区三区视频| 国产亚洲AV电影院之毛片| 欧美老少配性行为| 亚洲综合网中文字幕在线| 国产日韩久久免费影院| 97一区二区国产好的精华液| 贵阳市| 中文字幕亚洲无线码在线| 欧美成人午夜在线观看视频 | 亚洲成人资源在线观看| 国产69精品久久久久乱码免费| 欧美一区二区三区性视频| 精品超清无码视频在线观看| 97人妻免费碰视频碰免| 国产亚洲精品97在线视频一| 在线一区二区中文字幕| 亚洲男人第一无码av网| 日本精品网| 91青青草视频在线观看| 国产精品一品二区三四区| 99久久婷婷国产综合精品青草漫画 | 大桥未久亚洲无av码在线| 狠狠色综合久久狠狠色综合| 久久天天躁狠狠躁夜夜av不卡|