-
Notifications
You must be signed in to change notification settings - Fork 138
/
Horizontal.vue
93 lines (81 loc) 路 2.01 KB
/
Horizontal.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<template>
<div class="demo-horizontal-scroll-wrapper">
<CdkVirtualScroll
ref="listRef"
:dataSource="rowData"
:height="200"
:fullHeight="true"
:colWidth="80"
:bufferSize="20"
:bufferOffset="5"
:virtual="{ vertical: false, horizontal: true }"
:rowRender="rowRender"
getKey="key"
@scroll="onScroll"
@scrolledChange="onScrolledChange"
@scrolledBottom="onScrolledBottom"
>
<template #col="{ item, index }">
<span class="virtual-item" @click="onItemClick(item.key)">{{ item.key }} - {{ index }}</span>
</template>
</CdkVirtualScroll>
</div>
</template>
<script setup lang="ts">
import { h, ref } from 'vue'
import { VirtualRowRenderFn, VirtualScrollInstance } from '@idux/cdk/scroll'
const listRef = ref<VirtualScrollInstance>()
const data: { key: string }[] = []
for (let index = 0; index < 1000; index++) {
data.push({ key: `key-${index}` })
}
const rowData = [
{
key: 'row',
data,
},
]
const rowRender: VirtualRowRenderFn = ({ children }) =>
h(
'div',
{
class: 'virtual-row',
style: { display: 'flex', height: '100%', 'flex-wrap': 'nowrap' },
},
children,
)
const onScroll = (evt: Event) => {
console.log('scroll:', evt)
}
const onScrolledChange = (startIndex: number, endIndex: number, visibleData: { key: string }[]) =>
console.log('onScrolledChange', startIndex, endIndex, visibleData)
const onScrolledBottom = () => console.log('onScrolledBottom')
const onItemClick = (key: string) => {
console.log('click:', key)
}
</script>
<style lang="less">
.demo-horizontal-scroll-wrapper {
height: 240px;
.cdk-virtual-scroll {
border: 1px solid red;
margin-bottom: 8px;
}
.cdk-virtual-scroll-content {
height: 100%;
}
.virtual-row {
display: flex;
height: 100%;
flex-wrap: nowrap;
}
.virtual-item {
flex-shrink: 0;
padding-left: 16px;
border: 1px solid gray;
height: 100%;
width: 80px;
line-height: 18px;
}
}
</style>