DevLog
Python, TypeScript, etc...
MyPage
Python, TypeScript, etc...
2022/04/27

【Vuetify】Data table(v-data-table)の列固定

Vuetify
preview
@shiromisanta
Frontend Engineer
  •  /
目次
書き方

書き方

<template> <v-data-table class="fixed-column-table" :headers="tableHeader" :items="tableItems" item-key="id" fixed-header /> </template> <style lang="sass"> .fixed-column-table th:nth-child(1) position: sticky !important position: -webkit-sticky !important left: 0 z-index: 3 !important background: white border-right: 1px gray solid .fixed-column-table tr > td:nth-child(1) position: sticky !important position: -webkit-sticky !important left: 0 z-index: 3 !important background: white border-right: 1px gray solid .fixed-column-table tr > td white-space: nowrap max-width: 200px overflow: hidden text-overflow: ellipsis </style>

解説

まずはfixed-headerを指定したv-data-tableを配置する。

それに対してthおよびtdの先頭要素をstickyにすることでカラムの位置が固定される。

.fixed-column-table th:nth-child(1) position: sticky !important position: -webkit-sticky !important left: 0 z-index: 3 !important background: white border-right: 1px gray solid .fixed-column-table tr > td:nth-child(1) position: sticky !important position: -webkit-sticky !important left: 0 z-index: 3 !important background: white border-right: 1px gray solid

最後にセルの中身を改行させないようにして完成

.fixed-column-table tr > td white-space: nowrap max-width: 200px overflow: hidden text-overflow: ellipsis

関連記事

preview
@shiromisanta 2022/03/08
Vuetify
preview
@shiromisanta 2022/02/10
Vuetify
2022/04/27

【Vuetify】Data table(v-data-table)の列固定

Vuetify

書き方

<template> <v-data-table class="fixed-column-table" :headers="tableHeader" :items="tableItems" item-key="id" fixed-header /> </template> <style lang="sass"> .fixed-column-table th:nth-child(1) position: sticky !important position: -webkit-sticky !important left: 0 z-index: 3 !important background: white border-right: 1px gray solid .fixed-column-table tr > td:nth-child(1) position: sticky !important position: -webkit-sticky !important left: 0 z-index: 3 !important background: white border-right: 1px gray solid .fixed-column-table tr > td white-space: nowrap max-width: 200px overflow: hidden text-overflow: ellipsis </style>

解説

まずはfixed-headerを指定したv-data-tableを配置する。

それに対してthおよびtdの先頭要素をstickyにすることでカラムの位置が固定される。

.fixed-column-table th:nth-child(1) position: sticky !important position: -webkit-sticky !important left: 0 z-index: 3 !important background: white border-right: 1px gray solid .fixed-column-table tr > td:nth-child(1) position: sticky !important position: -webkit-sticky !important left: 0 z-index: 3 !important background: white border-right: 1px gray solid

最後にセルの中身を改行させないようにして完成

.fixed-column-table tr > td white-space: nowrap max-width: 200px overflow: hidden text-overflow: ellipsis

関連記事

preview
@shiromisanta
Frontend Engineer
  •  /
©︎Devlog