javascript - html table horizontal scroll enabling for specific columns - Stack Overflow

Lets consider the following image. I am generating a monthly report of working duration of employees..

Lets consider the following image. I am generating a monthly report of working duration of employees.. when the horizontal scrollbar is moved to the right, i want the code,name, area, territory column to be fixed on its position and the date columns should be horizontally scrollable. When scrolling right, the date columns should go underneath the code,name, area, territory column groups. How can i do it? Is there any css tricks or plugins available?

Lets consider the following image. I am generating a monthly report of working duration of employees.. when the horizontal scrollbar is moved to the right, i want the code,name, area, territory column to be fixed on its position and the date columns should be horizontally scrollable. When scrolling right, the date columns should go underneath the code,name, area, territory column groups. How can i do it? Is there any css tricks or plugins available?

Share asked Sep 30, 2019 at 7:52 Noob CoderNoob Coder 2,9178 gold badges39 silver badges64 bronze badges 1
  • 1 Possible duplicate of HTML table with horizontal scrolling (first column fixed) – user2039981 Commented Sep 30, 2019 at 7:58
Add a ment  | 

1 Answer 1

Reset to default 6

I think the most simple and logical way to fix columns according to @Circuit Breaker answer is

.view {
  margin: auto;
  width: 600px;
}

.wrapper {
  position: relative;
  overflow: auto;
  border: 1px solid black;
  white-space: nowrap;
}

.sticky-col {
  position: sticky;
  position: -webkit-sticky;    
  background-color: white;
}

.first-col {
  width: 100px;
  min-width: 100px;
  max-width: 100px;
  left: 0px;    
}

.second-col {
  width: 150px;
  min-width: 150px;
  max-width: 150px;
  left: 100px;    
}
<div class="view">
  <div class="wrapper"> 
    <table class="table">
      <thead>
        <tr>
          <th class="sticky-col first-col">Number</th>
          <th class="sticky-col second-col">First Name</th>
          <th>Last Name</th>
          <th>Employer</th>
       </tr>
      </thead>
       <tbody>
       <tr>
         <td class="sticky-col first-col">1</td>
         <td class="sticky-col second-col">Mark</td>
         <td>Ham</td>
         <td>Micro</td>
       </tr>
       <tr>
         <td class="sticky-col first-col">2</td>
         <td class="sticky-col second-col">Jacob</td>
         <td>Smith</td>
         <td>Adob Adob Adob AdobAdob Adob Adob Adob Adob</td>
       </tr>
       <tr>
         <td class="sticky-col first-col">3</td>
         <td class="sticky-col second-col">Larry</td>
         <td>Wen</td>
         <td>Goog Goog Goog GoogGoog Goog Goog Goog Goog Goog</td>
       </tr>
      </tbody>
    </table>
  </div>
</div>  

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744909365a4600451.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信