jQuery DataTable FixedHeader在可滚动容器中不起作用

时间:2016-12-05 08:09:20

标签: jquery twitter-bootstrap datatables

我正在使用Bootstrap和jQuery Datables。 我的表位于包含div(#dataContainer)

本身,FixedHeader工作得很好。 但是,如果我使容器固定高度和可滚动,我的数据表的固定头不再工作。 有点太愚蠢到不能绕过这个。 :-)所以希望以下代码有所帮助(如果我不调用“setupScrolling”,那么一切都很好)

  setupDataTables() {
    $('.datatable').DataTable( {
      "paging":     false,
      "searching":  false,
      "scrollX":    true,
      "info":       false,
      order:        [[ 1, "asc" ]],
      fixedHeader:  true
    });
  },

  // FIXED HEADER FOR ABOVE DATA TABLE DOES NOT WORK IF BELOW IS APPLIED TO THE DIV IT'S IN'
  setupScrolling() {
    if ($("#dataContainer").length ) {
        let content_height = $(window).height() - $("#dataContainer").offset().top -55;
        let otherheight = $("#dataContainer").height();
        if(otherheight > content_height) {
          $("#dataContainer").css({"max-height":content_height + 'px', "min-height":content_height + 'px'});
          $("#dataContainer").css({'overflow-x':'hidden','overflow-y':'scroll'});
        }
    }
  },

0 个答案:

没有答案