「DataTable」の利用方法
1.CDN経由でダウンロード
HTMLに以下のようにコードを記述します。
<head>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/bs4-4.1.1/jq-3.3.1/dt-1.10.18/sl-1.2.6/datatables.min.css"/>
<script type="text/javascript" src="https://cdn.datatables.net/v/bs4-4.1.1/jq-3.3.1/dt-1.10.18/sl-1.2.6/datatables.min.js"></script>
</head>
2.JS
一ページ当たりのレコード数を指定するプルダウンメニューの表示と、ページ保存の可否を設定する
スクリプトです。
HTMLのbody終了タグの直前あたりに書き込んで下さい。
id名はtableのidと同一にすることを忘れないで下さい。
<script type="text/javascript">
window.onload = function() {
var table = $('#example').DataTable({
// メニュー
"lengthMenu":[[5, 10, 25, 50, -1], [5, 10, 25, 50, "All"]],
// ページを保存
"stateSave":true
});
}
</script>
3.HTML
tableタグの記述例です。CSSはclass名を変更して自分好みにしてもかまいません。
tableのid名は2項のJSと同一にすることを忘れないで下さい。
参考:
「DataTables」
example.html
<table id="example" class="table table-striped table-bordered nowrap" width="100%">
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>Row 1 Data 1</td>
<td>Row 1 Data 2</td>
</tr>
<tr>
<td>Row 2 Data 1</td>
<td>Row 2 Data 2</td>
</tr>
</tbody>
</table>