javascript - Vuetify.js 数据表固定标题通过 CSS 滚动

标签 javascript html css vue.js vuetify.js

Vuetify's v-data-table component具有 fixed-header 功能,当 height 小于表格高度时,它会使标题变粘。

height 被显式设置时它是有效的。

HTML:

    <v-content id="mycontent">
      <v-container fluid id="mycontainer">
        <h2>Header</h2>
        <div id="outer">
          <v-data-table id="mytable" :headers="headers" :items="items" :height="height"
                        fixed-header disable-pagination disable-sort hide-default-footer>
          </v-data-table>
        </div>
      </v-container>
    </v-content>

CSS:

#mycontent {
}
#mycontainer {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#outer {
  flex: 1;
}
#mytable {
}
#mytable table {
  width: auto;
}

JS:

  data: () => ({
    headers: [
      { text: "Header A", value: "a" },
      { text: "Header B, longer", value: "b" },
      { text: "Header C", value: "c" }
    ],
    height: 100
  }),
  computed: {
    items() {
      var items = [];
      for (var i = 1; i <= 50; i++) {
        items.push({ a: "Row " + i, b: "Column B", c: "Column C" });
      }
      return items;
    }
  },
  methods: {
    onResize() {
      this.height = document.getElementById("outer").clientHeight;
    }
  },
  mounted() {
    window.addEventListener("resize", this.onResize);
    this.$nextTick(this.onResize);
  }

Live demo

但是是否可以使用纯 CSS 实现相同的效果,或者至少无需显式设置 height

最佳答案

尝试使用 height clac

.v-data-table__wrapper{height:calc(100vh - 150px) !important;}

关于javascript - Vuetify.js 数据表固定标题通过 CSS 滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57707812/

相关文章:

javascript - 将网页数据保存到本地文件: How can get data from a webpage into JSON file and be able to save that to local machine

php - 如何按设定的时间间隔重新解析 XML 文档?

javascript - 由 `ref` 调用的 React input.focus() 也调用 `onBlur` 事件

javascript - 通过javascript创建一个无序列表

javascript - 禁用 HTML5 弹出表单验证消息

css - 动态背景图片

jquery - 如何在div集合中获取特定的背景div

javascript - Bootstrap 3 - 如何使用 javascript/jquery 更改显示为工具提示的超链接标题文本?

javascript - 如何使用 ASP.NET MVC 通过 Ajax 将选中的行发送到服务器?

html - 背景图像上的动画延迟