使用的两个table实现表头固定表体滚动,并且实现表格的合并

当表格使用了跨行跨列合并时候不能同时使用display属性,不能实现tbody滚动效果,因此使用两个表格实现:

<div class="jcTable">
                <table  id="tableThead">
                        <tr>
                            <th >分类</th>
                            <th>指标名称</th>
                            <th>全省</th>
                            <th>南昌市</th>
                            <th>景德镇</th>
                            <th>萍乡市</th>
                            <th>九江市</th>
                            <th>新余市</th>
                            <th>鹰潭市</th>
                            <th>赣州市</th>
                            <th>吉安市</th>
                            <th>宜春市</th>
                            <th>抚州市</th>
                            <th>上饶市</th>
                        </tr>
                </table>
                <table id="tableId">
                    <tbody>
                        <tr v-for="(item,index) in tableData" :key="index">
                            <td class="tableId-td1">{{item.fenlei}}</td>
                            <td class="tableId-td2">{{item.zbmc}}</td>
                            <td>{{item.qs}}</td>
                            <td><div :class="[item.ncs==0? 'yuan0':item.ncs==1? 'yuan1':item.ncs==2? 'yuan2':'']"></div></td>
                            <td><div :class="[item.jdz==0? 'yuan0':item.jdz==1? 'yuan1':item.jdz==2? 'yuan2':'']"></div></td>
                            <td><div :class="[item.pxs==0? 'yuan0':item.pxs==1? 'yuan1':item.pxs==2? 'yuan2':'']"></div></td>
                            <td><div :class="[item.jjs==0? 'yuan0':item.jjs==1? 'yuan1':item.jjs==2? 'yuan2':'']"></div></td>
                            <td><div :class="[item.xys==0? 'yuan0':item.xys==1? 'yuan1':item.xys==2? 'yuan2':'']"></div></td>
                            <td><div :class="[item.yts==0? 'yuan0':item.yts==1? 'yuan1':item.yts==2? 'yuan2':'']"></div></td>
                            <td><div :class="[item.tzs==0? 'yuan0':item.tzs==1? 'yuan1':item.tzs==2? 'yuan2':'']"></div></td>
                            <td><div :class="[item.jas==0? 'yuan0':item.jas==1? 'yuan1':item.jas==2? 'yuan2':'']"></div></td>
                            <td><div :class="[item.ycs==0? 'yuan0':item.ycs==1? 'yuan1':item.ycs==2? 'yuan2':'']"></div></td>
                            <td><div :class="[item.fzs==0? 'yuan0':item.fzs==1? 'yuan1':item.fzs==2? 'yuan2':'']"></div></td>
                            <td><div :class="[item.srs==0? 'yuan0':item.srs==1? 'yuan1':item.srs==2? 'yuan2':'']"></div></td>
                        </tr>
                    </tbody>
                </table>

css:

.jcTable {
        width: 3120px;
        height: 1384px;
        margin: auto;
        margin-top: 40px;
        color: #000 !important;
        #tableThead{
            width: 100%;
            border-spacing: 0;
            border-collapse: separate;
            & tr{
                width: 100%;
                height: 128px;
                background: url(../assets/images/bg-thead.png) no-repeat;
                background-size: 100% 100%;
                border: 2px solid rgba(152,198,255,1);
            }
            & tr th{
                font-family: PingFangSC-Regular;
                font-size: 32px;
                color: #FFFFFF;
                font-weight: 400;
                text-align: center;
                border: 2px solid rgba(152,198,255,1);
            }
            & tr th{
                width: 175px;
            }
            & tr th:nth-child(1){
                width: 268px;
            }
            & tr th:nth-child(2){
                width: 748px;
            }
 
        }
        #tableId {
            width: 100%;
            height: calc(1384px - 128px);
            border-spacing: 0;
            border-collapse: separate;
            overflow-y: overlay;
            display: inline-block;
            & td {
                border: 2px solid rgba(152,198,255,1);
                font-family: PingFangSC-Regular;
                font-size: 32px;
                color: #FFFFFF;
                font-weight: 400;
                text-align: center;
            }
            & tr td{
                width: 175px;
            }
            & tr .tableId-td1{
                width: 268px;
            }
            & tr .tableId-td2{
                width: 748px;
            }
           
            &  tr{
                height: 98px;
            }
            &  tr:nth-child(2n) {
                background: rgba(50,197,255,0.08);
            }
            &  tr td div{
                margin: auto;
            }
            &  tr td .yuan0{
                width: 32px;
                height: 32px;
                background: rgba(255,0,67,0.60);
                border: 2px solid rgba(255,0,67,1);
                box-shadow: 0px 4px 8px 0px rgba(0,0,0,0.19);
                border-radius: 50%;
            }
            &  tr td .yuan1{
                width: 32px;
                height: 32px;
                background: rgba(248,182,12,0.60);
                border: 2px solid rgba(248,182,12,1);
                box-shadow: 0px 4px 8px 0px rgba(0,0,0,0.19);
                border-radius: 50%;
            }
            &  tr td .yuan2{
                width: 32px;
                height: 32px;
                background: rgba(47,250,182,0.60);
                border: 2px solid rgba(47,250,182,1);
                box-shadow: 0px 4px 8px 0px rgba(0,0,0,0.19);
                border-radius: 50%;
            }
        }
 
    }

合并的代码在原生table动态数据,通过jQuery实现相同数据时候跨行合并

效果图:

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在 Bootstrap 中,可以使用固定表头滚动表体的插件来实现这个效果。以下是实现步骤: 1. 引入必要的文件: ``` <link rel="stylesheet" href="https://cdn.staticfile.org/bootstrap/4.3.1/css/bootstrap.min.css"> <script src="https://cdn.staticfile.org/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdn.staticfile.org/popper.js/1.14.7/umd/popper.min.js"></script> <script src="https://cdn.staticfile.org/bootstrap/4.3.1/js/bootstrap.min.js"></script> ``` 2. 创建一个表格,并在表格头部添加 `thead` 标签: ``` <table class="table table-bordered table-striped"> <thead> <tr> <th>列头1</th> <th>列头2</th> <th>列头3</th> </tr> </thead> <tbody> <tr> <td>行1列1</td> <td>行1列2</td> <td>行1列3</td> </tr> <tr> <td>行2列1</td> <td>行2列2</td> <td>行2列3</td> </tr> <!-- more rows --> </tbody> </table> ``` 3. 使用 JavaScript 初始化表格,并调用插件: ``` $(function() { $('.table').fixedHeaderTable({ fixedColumn: true }); }); ``` 其中,`fixedHeaderTable` 是插件名称,`fixedColumn: true` 表示需要固定表头。 4. 根据需要调整样式: ``` .table-fixed-header { overflow-y: auto; max-height: 400px; } .table-fixed-header thead th, .table-fixed-header tbody td { width: 100px; min-width: 100px; max-width: 100px; } ``` 其中,`.table-fixed-header` 是插件自动生成的类名,可以根据需要进行修改。 完整代码如下: ``` <!DOCTYPE html> <html> <head> <title>Bootstrap Table 表头固定表体滚动</title> <meta charset="utf-8"> <link rel="stylesheet" href="https://cdn.staticfile.org/bootstrap/4.3.1/css/bootstrap.min.css"> <style> .table-fixed-header { overflow-y: auto; max-height: 400px; } .table-fixed-header thead th, .table-fixed-header tbody td { width: 100px; min-width: 100px; max-width: 100px; } </style> </head> <body> <div class="container"> <table class="table table-bordered table-striped table-fixed-header"> <thead> <tr> <th>列头1</th> <th>列头2</th> <th>列头3</th> </tr> </thead> <tbody> <tr> <td>行1列1</td> <td>行1列2</td> <td>行1列3</td> </tr> <tr> <td>行2列1</td> <td>行2列2</td> <td>行2列3</td> </tr> <!-- more rows --> </tbody> </table> </div> <script src="https://cdn.staticfile.org/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdn.staticfile.org/popper.js/1.14.7/umd/popper.min.js"></script> <script src="https://cdn.staticfile.org/bootstrap/4.3.1/js/bootstrap.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/fixed-header-table@1.3.2/dist/fixed-header-table.min.js"></script> <script> $(function() { $('.table').fixedHeaderTable({ fixedColumn: true }); }); </script> </body> </html> ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值