여러 요소가있는 것이 유효 할 수 있지만 고정 머리글 / 바닥 글이있는 스크롤 가능한 그리드를 만들려는 경우 다음이 작동하지 않을 수 있습니다. 이 코드는 다음 CSS, jquery 및 AngularJS를 가정합니다.
HTML
<table id="tablegrid_ko">
<thead>
<tr>
<th>
Product Title
</th>
<th>
</th>
</tr>
</thead>
<tbody ng-repeat="item in itemList">
<tr ng-repeat="itemUnit in item.itemUnit">
<td>{{itemUnit.Name}}</td>
</tr>
</tbody>
</table>
스크롤 가능한 표 그리드를위한 고정 머리글 / 바닥 글을 작성하는 CSS
#tablegrid_ko {
max-height: 450px;
}
#tablegrid_ko
{
border-width: 0 0 1px 1px;
border-spacing: 0;
border-collapse: collapse;
border-style: solid;
}
#tablegrid_ko td, #tablegrid_ko th
{
margin: 0;
padding: 4px;
border-width: 1px 1px 0 0;
border-style: solid;
}
#tablegrid_ko{border-collapse:separate}
#tablegrid_ko tfoot,#tablegrid_ko thead{z-index:1}
#tablegrid_ko tbody{z-index:0}
#tablegrid_ko tr{height:20px}
#tablegrid_ko tr >td,#tablegrid_ko tr >th{
border-width:1px;border-style:outset;height:20px;
max-height:20px;xwidth:45px;xmin-width:45px;xmax-width:45px;white-space:nowrap;overflow:hidden;padding:3px}
#tablegrid_ko tr >th{
background-color:#999;border-color:#2c85b1 #18475f #18475f #2c85b1;color:#fff;font-weight:bold}
#tablegrid_ko tr >td{background-color:#fff}
#tablegrid_ko tr:nth-child(odd)>td{background-color:#f3f3f3;border-color:#fff #e6e6e6 #e6e6e6 #fff}
#tablegrid_ko tr:nth-child(even)>td{background-color:#ddd;border-color:#eaeaea #d0d0d0 #d0d0d0 #eaeaea}
div.scrollable-table-wrapper{
background:#268;border:1px solid #268;
display:inline-block;height:285px;min-height:285px;
max-height:285px;width:550px;position:relative;overflow:hidden;padding:26px 0}
div.scrollable-table-wrapper table{position:static}
div.scrollable-table-wrapper tfoot,div.scrollable-table-wrapper thead{position:absolute}
div.scrollable-table-wrapper thead{left:0;top:0}
div.scrollable-table-wrapper tfoot{left:0;bottom:0}
div.scrollable-table-wrapper tbody{display:block;position:relative;overflow-y:scroll;height:283px;width:550px}
tbody의 수평 스크롤링을 바인딩하는 Jquery는 tbody가 ng-repeat 중에 반복되기 때문에 작동하지 않습니다.
$(function ($) {
$.fn.tablegrid = function () {
var $table = $(this);
var $thead = $table.find('thead');
var $tbody = $table.find('tbody');
var $tfoot = $table.find('tfoot');
$table.wrap("<div class='scrollable-table-wrapper'></div>");
$tbody.bind('scroll', function (ev) {
var $css = { 'left': -ev.target.scrollLeft };
$thead.css($css);
//$tfoot.css($css);
});
}; // plugin function
}(jQuery));