Horizontal and vertical Scroll-able table in Bootstrap

前端 未结 1 1285
野趣味
野趣味 2021-02-15 23:33

I am designing a table using bootstrap, responsive one. Till it has less no. of columns, it was good. With fixed header, it was working fine.

JSFIDDLE VERTICAL SCROLLBAR<

1条回答
  •  花落未央
    2021-02-16 00:30

    After a while, i got one solution for my query.. Solution to make table scroll-able vertically and horizontally and responsive

    $('table').on('scroll', function() {
      $("#" + this.id + " > *").width($(this).width() + $(this).scrollLeft());
    });
    html {
      font-family: verdana;
      font-size: 10pt;
      line-height: 25px;
    }
    
    table {
      border-collapse: collapse;
      width: 300px;
      overflow-x: scroll;
      display: block;
    }
    
    thead {
      background-color: #EFEFEF;
    }
    
    thead,
    tbody {
      display: block;
    }
    
    tbody {
      overflow-y: scroll;
      overflow-x: hidden;
      height: 140px;
    }
    
    td,
    th {
      min-width: 100px;
      height: 25px;
      border: dashed 1px lightblue;
      overflow: hidden;
      text-overflow: ellipsis;
      max-width: 100px;
    }
    
    
    
    
    sadasdasdfasdfasfasfasfa# Firstname Lastname Age City Country # Firstname Lastname Age City Country
    1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA
    1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA
    1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA
    1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA
    1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA
    1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA
    1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA
    1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA
    1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA
    1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA
    sadasdasdfasdfasfasfasfa# Firstname Lastname Age City Country # Firstname Lastname Age City Country
    1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA
    1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA
    1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA
    1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA
    1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA
    1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA
    1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA
    1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA
    1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA
    1 Anna Pitt 35 New York USA 1 Anna Pitt 35 New York USA

    Note: Go to the jsFiddle to view it better.

    0 讨论(0)
提交回复
热议问题