Table fixed header and scrollable body

前端 未结 29 1703
粉色の甜心
粉色の甜心 2020-11-22 05:33

I am trying to make a table with fixed header and a scrollable content using the bootstrap 3 table. Unfortunately the solutions I have found does not work with bootstrap or

29条回答
  •  余生分开走
    2020-11-22 05:47

    An easy way without fixed width:

    .myTable tbody{
      display:block;
      overflow:auto;
      height:200px;
      width:100%;
    }
    .myTable thead tr{
      display:block;
    }
    

    Source

    Now, on onLoad, to adjust th widths, just add this jquery script:

    $.each($('.myTable tbody tr:nth(0) td'), function(k,v) {
        $('.myTable thead th:nth('+k+')').css('width', $(v).css('width'));
    });
    

提交回复
热议问题