element-plus/docs/examples/table-v2/sticky-rows.vue
JeremyWuuuuu 2d4c52e352
docs(components): [virtual-table] documentations (#7386)
* docs(components): [virtual-table] documentations

- Add examples for `sticky-rows`.
- Add examples for `fixed-columns`.

* Remove style language marking
2022-04-26 14:16:46 +08:00

47 lines
983 B
Vue

<template>
<table-v2
:columns="columns"
:data="tableData"
:fixed-data="fixedData"
:width="700"
:height="400"
:row-class="rowClass"
fixed
@scroll="onScroll"
/>
</template>
<script lang="ts" setup>
import { computed, ref } from 'vue'
import { TableV2 } from '@element-plus/components/table-v2'
import { generateColumns, generateData } from './utils'
const columns = generateColumns(10)
const data = generateData(columns, 200)
const rowClass = ({ rowIndex }) => {
if (rowIndex < 0 || (rowIndex + 1) % 5 === 0) return 'sticky-row'
}
const stickyIndex = ref(0)
const fixedData = computed(() =>
data.slice(stickyIndex.value, stickyIndex.value + 1)
)
const tableData = computed(() => {
return data.slice(1)
})
const onScroll = ({ scrollTop }) => {
stickyIndex.value = Math.floor(scrollTop / 250) * 5
}
</script>
<style>
.el-table-v2__fixed-header-row {
background-color: var(--el-color-primary-light-5);
font-weight: bold;
}
</style>