【问题标题】:Fix the headers in a responsive table angularjs修复响应表 angularjs 中的标题
【发布时间】:2017-07-26 11:05:01
【问题描述】:

我是webDevelopment. 的新手,在发布此之前,我已经阅读了所有答案,但没有一个对我有用。所以,我在问这个问题。我有一张桌子,我在其中添加了

overflow-y:scroll;
height:100px;

使用这个我得到滚动条,但我的表格标题不固定。那么,有人可以帮我解决这个问题吗?

<div class="col-xs-12 col-md-12 nopadding">
    <div class="table-responsive">
        <table class="table table-striped table-bordered col-xs-12 col-lg-12">
            <thead class="text-center text-info text-capitalize">
            <th class="text-center">Sr.No.</th>
            <th class="text-center">Document</th>
            <th class="text-center">Score</th>
            <th class="text-center">Actions</th>
            </thead>
            <tr ng-repeat="file in processResumeFiles">
                <td class="text-center">{{ file.id}}</td>
                <td class="view-orphan uploadResumeTableCellOverFlow">
                    {{ file.attributes.name}}
                </td>
                <td class="text-center">{{file.totalScore}}</td>
                <td class="text-center">
                    <button class="btn btn-labeled  btn-info" title="click to see" ng-disabled="!file.attributes.isUploadedDocument" data-ng-click="somemethod($index)">
                        <i class="fa fa-eye" aria-hidden="true"></i>
                    </button>
                    <button class="btn btn-labeled  btn-info" title="click to see" ng-disabled="!file.attributes.isCommitted || !file.attributes.isUploadedDocument" data-ng-click="somemethod(file.attributes.name)">
                        <i class="fa fa-share" aria-hidden="true"></i>
                    </button>
                    <button class="btn btn-labeled  btn-info" title="click to see" data-ng-click="somemethod(file.attributes.name)">
                        <i class="fa fa-trash" aria-hidden="true"></i>
                    </button>
                    <button class="btn btn-labeled  btn-info" title="click to see" ng-disabled="!file.attributes.isCommitted || !file.attributes.isUploadedDocument" data-ng-click="somemethod(file.attributes.name)">
                        <i class="fa fa-sign-out" aria-hidden="true"></i>
                    </button>
                    <button class="btn btn-labeled  btn-info" title="click to see" ng-disabled="!file.attributes.isCommitted || !isjdDeleted || !jdSelected"
                            data-ng-click="somemethod(file.attributes.name)">
                        <i class="fa fa-check-square" aria-hidden="true"></i>
                    </button>
                </td>
            </tr>
        </table>
    </div>
</div>

【问题讨论】:

  • 您为什么希望它们得到修复?您可以做的只是在tbody 上设置overflow-y: scroll; 而不是表格元素,但这需要将元素显示为block
  • 因为在 ng-repeat 表中有超过 100 个条目,所以我只想为该表添加一个滚动条。正因为如此,我希望标题应该是固定的。
  • 无法在 tbody 上使用 overflow-y:scroll
  • 正如我所说,您还需要display: block,但这会造成很大的伤害
  • 试过..但它只是移动标题的位置。

标签: javascript jquery html css angularjs


【解决方案1】:

这里有一个 jQuery 插件可以为您完成这项工作:fixed header table

【讨论】:

    【解决方案2】:

    你可以试试这个:

    .table-fixed thead {
      width: 97%;
    }
    .table-fixed tbody {
      height: 230px;
      overflow-y: auto;
      width: 100%;
    }
    .table-fixed thead, .table-fixed tbody, .table-fixed tr, .table-fixed td, .table-fixed th {
      display: block;
    }
    .table-fixed tbody td, .table-fixed thead > tr> th {
      float: left;
      border-bottom-width: 0;
    }
    

    【讨论】:

      【解决方案3】:

      试试这个

      table {
          width: 100%;
      }
      
      thead, tbody, tr, td, th { display: block; }
      
      tr:after {
          content: ' ';
          display: block;
          visibility: hidden;
          clear: both;
      }
      
      thead th {
          height: 30px;
          text-align: left;
      }
      
      tbody {
          height: 120px;
          overflow-y: auto;
      }
      
      thead {
          /* fallback */
      }
      
      
      tbody td, thead th {
          width: 19.2%;
          float: left;
      }
      

      你在小提琴中看到https://jsfiddle.net/zLgzwn56/

      【讨论】:

      • 在此之后,列标题与数据未对齐,此问题正在发生。
      • thead th { 删除对text-align 的评论,请检查更新后的代码
      • 对 css 使用 less 文件。所以,像 .table 一样使用它不知道如何使用 thead, tbody, tr, td, th { display: block; } 在较少的文件中
      • 这个东西没有固定标题
      • 在这样做之后,如果标题未对齐,我仍然会遇到同样的问题。
      【解决方案4】:

      首先将:table-layout: fixed; 添加到您的表格元素中。

      同样为了语义正确,为表格上的内容添加 tbody(在您的示例中缺少)。

      然后给 tbody 添加overflow: auto; 和一个高度。参见示例:https://codepen.io/tjvantoll/pen/JEKIu

      【讨论】:

      • 嘿,我用过 .tableBodyScroll tbody { display:block;最大高度:300px;溢出-y:滚动; } .tableBodyScroll thead, tbody tr { display:table;宽度:100%;表格布局:固定;这个css,现在的问题是标题与正文内容的对齐。列标题与数据不对齐。你能告诉我为什么吗?
      • 如果不查看您当前的 HTML 就很难知道 - 您可能会丢失一些单元格。使用实际标记创建一个 codepen,它可能更容易提供帮助。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-06
      • 1970-01-01
      • 1970-01-01
      • 2019-04-30
      相关资源
      最近更新 更多