テーブルのヘッダを常に表示させるjQueryプラグインを作ってみた
- September 17th, 2014
 
テーブルのヘッダを固定させる方法を探していたのですが、「thead」と「tbody」を分けた方法や、テーブルの幅が固定された方法しか見つけられなかったので、jQueryプラグインを試しに作ってみました。
jquery.smTheadfixed.js
対応するテーブルは、theadタグとtbodyタグを使った単純なテーブルで、rowspanやcolspanを使わないテーブルを想定しています。
テーブルの横幅は、固定と可変どちらでも対応するようにしています。
Options
| Name | Default | Description | 
|---|---|---|
| border_top | 0 (number) | 上辺ボーダーの幅を指定 | 
| border_left | 0 (number) | 左辺ボーダーの幅を指定 | 
| thead_row | 0 (number) | theadの基準行番号 | 
| tbody_row | 0 (number) | tbodyの基準行番号 | 
記述例
tableタグにクラス名を指定、theadタグとtbodyタグを使用する。
<script type="text/javascript">
//<![CDATA[
    $(function(){
        $('.jsTheadfixed').smTheadfixed();
    });
//]]>
</script>
<table class="jsTheadfixed">
    <thead>
        <tr>
            <th>ID</th>
            <th>Name</th>
            <th>Date</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>1</td>
            <td>AAA</td>
            <td>2014-01-01</td>
        </tr>
        <tr>
            <td>2</td>
            <td>BBB</td>
            <td>2014-02-01</td>
        </tr>
        <tr>
            <td>3</td>
            <td>CCC</td>
            <td>2014-03-01</td>
        </tr>
    </tbody>
</table>- September 17th, 2014
 
