简体   繁体   English

角材料固定表头

[英]Angular Material fixed table header

This appears to be a know issue but there doesn't seem to be a solution yet. 这似乎是一个已知问题,但似乎还没有解决方案。 after installing the Angular fixed table header to keep the column titles visible. 在安装Angular固定表标题后,保持列标题可见。 when I add the fix-head attribute to the <thead> this error appears in the console: 当我将fix-head属性添加到<thead>此错误出现在控制台中:

Controller 'mdtable', required by directive 'mdcolumn', can't be found thead md-head="" md-order hidden;" 找不到指令'mdcolumn'所需的控制器'mdtable'thead md-head =“ =” md-order hidden;“

From the research I've it seems to have to do with ui-router or ng-if. 根据我的研究,似乎与ui-router或ng-if有关。 In my case it works for my first page when the browser reloads but on my other pages I get this issue in the console. 就我而言,它在重新加载浏览器时适用于我的第一页,但是在其他页面上,我在控制台中遇到此问题。 Here is the site I used to install the fixed header: https://github.com/daniel-nagy/fixed-table-header 这是我用来安装固定标头的网站: https : //github.com/daniel-nagy/fixed-table-header

我发现如果用ng-if或ui-view将其包裹在div上是行不通的

i just added another table with the same setting and no data source. 我只是添加了另一个具有相同设置且没有数据源的表。 just mention that in css style position of new table is absolute and an empty is also added because without that this new table would cover a part of scrollbar. 只需提及在CSS样式中,新表的位置是绝对的,并且还添加了一个空白,因为如果没有该表,则新表将覆盖滚动条的一部分。 CSS: CSS:

.tables {
height: inherit;
position: relative;
display: flex;
width: 100%;
}
.table {
overflow: auto;
height: 100%;
width: 100%;
position: relative;
}
.full-width {
width: 100%;
}
.header-table {
position: relative;
width: 100%;
}
.header {
display: flex;
flex-direction: row;
position: absolute;
width: 100%;
  }

html code:

<div class="tables">
    <md-table
  [dataSource]="dataSource"
  class="table">
   //columns and header definitions.
</md-table> 
<div class="header">
  <md-table #table
    class="header-table">
    //the same definition for columns and header.
  </md-table>
  <div class="scroll-wrapper"></div>//div that covers the scrollbar.
</div>

image 图片

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM