tableタグでスクロール時にヘッダーを残して表示する方法(jquery-decapitate)
2024/01/13
テーブルタグ内で縦にスクロールした際にテーブルヘッダー部分は表示させたままテーブルボディーをスクロールさせたい。jQuery decapitateというプラグインで実装できる模様。以下に実装方法をメモ。
ダウンロード先
https://github.com/claymation/jquery-decapitate
サンプル
https://taitan916.info/sample/decapitate/
ソース
<?php
function makeRandStr($length) {
$r_str = '';
$str = array_merge(range('a', 'z'), range('0', '9'), range('A', 'Z"'));
for ($x = 0; $x < $length; $x++) {
$r_str .= $str[rand(0, count($str)-1)];
}
return $r_str;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>jquery-decapitate</title>
<link href="bootstrap.min.css" rel="stylesheet" type="text/css" />
<link href="bootstrap-responsive.min.css" rel="stylesheet" type="text/css" />
<link href="jquery.decapitate.css" rel="stylesheet" type="text/css" />
<link href="styles.css" rel="stylesheet" type="text/css" />
<script src="jquery.min.js"></script>
<script src="bootstrap-affix.js"></script>
<script src="jquery.decapitate.js"></script>
<script>
$(document).ready(function() {
$('table').decapitate();
});
</script>
</head>
<body>
<table id="element-table" class="table table-bordered">
<thead>
<tr>
<th>seq</th>
<th>str</th>
<th>tag</th>
</tr>
</thead>
<tbody>
<?php for($i = 0; $i < 100; $i++){ ?>
<tr>
<td><?php echo $i;?></td>
<td><?php echo makeRandStr(5);?></td>
<td><?php echo ($i % 2 == 0) ? 'aaa': 'bbb';?></td>
</tr>
<?php } ?>
</tbody>
</table>
</body>
</html>
関連記事
-
-
Ajaxで負荷軽減
業務中、専用のページでfile_get_contents的なものは あまり使わな ...
-
-
jquery.cookie.jsで保存期間を時間指定する方法
jquery.cookie.jsで保存期間を1時間等、時間指定したい。公式サイト ...
-
-
Lightboxで画像拡大時に閉じるボタンの位置を右上に変更
Lightbox(バージョン2.7.1)で画像拡大時に閉じるボタンの位置を右下か ...
-
-
「jQuery.browser is undefined」エラーの対応方法
jQueryのプラグインを使っていて1.9以降だと「jQuery.browser ...
-
-
ラジオボタンのカスタムデータ属性を取得し、特定の値の場合はチェックさせない方法
ASPを使用したサイトで特定のradioボタンは選択不可にしたいというケースがあ ...