利用bootstrap-table 表格表头固定

前端 · 07-17
客户的需求是探索的动力。

利用bootstrap-table来固定表头 在table设置 data-height data-fixed-scroll 属性即可。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-table@1.23.1/dist/bootstrap-table.min.css">
    <script src="https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js" ></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap-table@1.23.1/dist/bootstrap-table.min.js"></script>
    <style>
        td{
            text-align: center;
        }
    </style>
</head>

<body>
    <div id="toolbar">
        <button id="button" class="btn btn-secondary">load</button>
    </div>
    <table id="table" data-toggle="table" data-toolbar="#toolbar" data-height="200" data-fixed-scroll="true"
        >
        <thead>
            <tr>
                <th data-field="id">ID</th>
                <th data-field="name">Item Name</th>
                <th data-field="price">Item Price</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>123213123123</td>
                <td>123213123123</td>
                <td>123213123123</td>    
            </tr>
            <tr>
                <td>123213123123</td>
                <td>123213123123</td>
                <td>123213123123</td>    
            </tr>
            <tr>
                <td>123213123123</td>
                <td>123213123123</td>
                <td>123213123123</td>    
            </tr>
            <tr>
                <td>123213123123</td>
                <td>123213123123</td>
                <td>123213123123</td>    
            </tr>
            <tr>
                <td>123213123123</td>
                <td>123213123123</td>
                <td>123213123123</td>    
            </tr>
            <tr>
                <td>123213123123</td>
                <td>123213123123</td>
                <td>123213123123</td>    
            </tr>
            <tr>
                <td>123213123123</td>
                <td>123213123123</td>
                <td>123213123123</td>    
            </tr>
            <tr>
                <td>123213123123</td>
                <td>123213123123</td>
                <td>123213123123</td>    
            </tr>
        </tbody>
    </table>
</body>
</html>

https://examples.bootstrap-table.com/#options/fixed-scroll.html#view-source
表格组件神器:bootstrap table详细使用指南

bootstrap
Theme Jasmine by Kent Liao