나는 최근 비슷한 문제가 있었고 다른 솔루션을 혼합하여 문제를 해결했습니다.
첫 번째이자 가장 간단한 것은 두 개의 테이블을 사용하는 것이 었습니다. 이것은 작동하지만 헤더와 본문 열이 정렬되지 않았습니다. 그리고 트위터 부트 스트랩 테이블과 함께 제공되는 자동 크기를 사용하고 싶기 때문에 다음과 같은 경우 헤더를 변경하는 Javascript 함수를 만들었습니다. 창 크기가 조정됩니다. 열의 데이터 변경 등
내가 사용한 코드 중 일부는 다음과 같습니다.
<table class="table table-striped table-hover" style="margin-bottom: 0px;">
<thead>
<tr>
<th data-sort="id">Header 1</i></th>
<th data-sort="guide">Header 2</th>
<th data-sort="origin">Header 3</th>
<th data-sort="supplier">Header 4</th>
</tr>
</thead>
</table>
<div class="bodycontainer scrollable">
<table class="table table-hover table-striped table-scrollable">
<tbody id="rows"></tbody>
</table>
</div>
헤더와 본문은 두 개의 별도 테이블로 나뉩니다. 그중 하나는 수직 스크롤 막대를 생성하는 데 필요한 스타일을 가진 DIV 내부에 있습니다. 내가 사용한 CSS는 다음과 같습니다.
.bodycontainer {
//height: 200px
width: 100%;
margin: 0;
}
.table-scrollable {
margin: 0px;
padding: 0px;
}
페이지 높이에 관계없이 테이블이 페이지 하단에 도달하기를 원했기 때문에 여기에 높이를 주석으로 표시했습니다.
헤더에 사용 된 데이터 정렬 속성도 모든 td에서 사용됩니다. 이렇게하면 모든 td의 너비와 패딩과 행의 너비를 얻을 수 있습니다. 데이터 정렬 속성을 사용하여 CSS를 사용하여 각 헤더의 패딩과 너비와 스크롤 막대가 없기 때문에 항상 더 큰 헤더 행의 너비를 설정했습니다. 커피 스크립트를 사용하는 기능은 다음과 같습니다.
fixHeaders: =>
for header, i in @headers
tdpadding = parseInt(@$("td[data-sort=#{header}]").css('padding'))
tdwidth = parseInt(@$("td[data-sort=#{header}]").css('width'))
@$("th[data-sort=#{header}]").css('padding', tdpadding)
@$("th[data-sort=#{header}]").css('width', tdwidth)
if (i+1) == @headers.length
trwidth = @$("td[data-sort=#{header}]").parent().css('width')
@$("th[data-sort=#{header}]").parent().parent().parent().css('width', trwidth)
@$('.bodycontainer').css('height', window.innerHeight - ($('html').outerHeight() -@$('.bodycontainer').outerHeight() ) ) unless @collection.length == 0
여기서는 @headers라는 헤더 배열이 있다고 가정합니다.
예쁘지는 않지만 작동합니다. 그것이 누군가를 돕기를 바랍니다.