Skip to content

Commit dd58712

Browse files
committed
bug fixes, readme
1 parent 073cbfe commit dd58712

File tree

6 files changed

+190
-88
lines changed

6 files changed

+190
-88
lines changed

README.md

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,179 @@
11
# vue-windowing
22

33
Set of components used for virtualizing DOM.
4+
5+
# Installation
6+
7+
```
8+
npm install --save vue-windowing
9+
```
10+
11+
## Import
12+
13+
Install all as a plugin:
14+
15+
```javascript
16+
import Vue from 'vue'
17+
import ViewWindowing from 'vue-windowing';
18+
19+
Vue.use(ViewWindowing)
20+
```
21+
22+
Install only those which you want:
23+
24+
```javascript
25+
import Vue from 'vue'
26+
import {
27+
VirtualScroll,
28+
// ...
29+
NestedList,
30+
} from 'vue-windowing';
31+
32+
Vue.component(VirtualScroll, 'VirtualScroll');
33+
Vue.component(NestedList, 'NestedList');
34+
```
35+
36+
# Usage
37+
38+
There are several components used for DOM virtualization:
39+
40+
## VirtualScroll
41+
42+
Component used for virtualizing vertical scrolling elements. It may handle dynamic height elements calculated on fly by AutoHeightMeasurer.
43+
44+
Example:
45+
46+
```vue
47+
<template>
48+
<VirtualScroll
49+
:items="items"
50+
:root-height="rootHeight"
51+
:render-ahead="renderAhead"
52+
:estimated-height="estimatedHeight">
53+
<template #item="{ item, index}">
54+
<div v-text="item" />
55+
</template>
56+
</VirtualScroll>
57+
</template>
58+
59+
<script>
60+
export default {
61+
data() {
62+
return {
63+
items: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],
64+
rootHeight: 100,
65+
renderAhead: 2, // Buffer, +2 at top / bottom in queue
66+
estimatedHeight: 20, // We need to assume that there is some default height for each row which will be recalculated later
67+
};
68+
},
69+
}
70+
</script>
71+
```
72+
73+
## NestedList
74+
75+
Wrapper for VirtualScroll. It adds simple functionality of flattening passed items.
76+
77+
Example:
78+
79+
```vue
80+
<template>
81+
<NestedList
82+
:items="items"
83+
:root-height="rootHeight"
84+
:render-ahead="renderAhead"
85+
:estimated-height="estimatedHeight">
86+
<template #group="{ item, index }">
87+
<h3 v-text="item" />
88+
</template>
89+
<template #item="{ item, index }">
90+
<div v-text="item" />
91+
</template>
92+
</NestedList>
93+
</template>
94+
95+
<script>
96+
export default {
97+
data() {
98+
return {
99+
items: {
100+
numberGroup: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],
101+
stringGroup: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14'],
102+
},
103+
rootHeight: 100,
104+
renderAhead: 2, // Buffer, +2 at top / bottom in queue
105+
estimatedHeight: 20, // We need to assume that there is some default height for each row which will be recalculated later
106+
};
107+
},
108+
}
109+
</script>
110+
```
111+
112+
## ExpandingList
113+
114+
Wrapper for VirtualScroll. It adds simple functionality of flattening passed items and toggling visibility of groups.
115+
116+
Example:
117+
118+
```vue
119+
<template>
120+
<ExpandingList
121+
:items="items"
122+
:root-height="rootHeight"
123+
:render-ahead="renderAhead"
124+
:estimated-height="estimatedHeight"
125+
:expanded-group="expandedGroup"
126+
@expand="onExpandGroup">
127+
<template #group="{ item, index }">
128+
<div v-text="item" />
129+
</template>
130+
<template #item="{ item, index }">
131+
<div v-text="item" />
132+
</template>
133+
</ExpandingList>
134+
</template>
135+
136+
<script>
137+
export default {
138+
data() {
139+
return {
140+
items: {
141+
numberGroup: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],
142+
stringGroup: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14'],
143+
},
144+
rootHeight: 100,
145+
renderAhead: 2, // Buffer, +2 at top / bottom in queue
146+
estimatedHeight: 20, // We need to assume that there is some default height for each row which will be recalculated later
147+
expandedGroup: '',
148+
};
149+
},
150+
methods: {
151+
expandedGroup(group) {
152+
// You may fetch data here and mutate items object
153+
// this.items[group] = ['a', 'b', 'c', 'd'];
154+
155+
this.expandedGroup = group;
156+
}
157+
}
158+
}
159+
</script>
160+
```
161+
162+
Props:
163+
164+
| Prop name | Description | Default value |
165+
| ------------- |:-------------:| -----:|
166+
| items | list of items | [] or {} for Nested/Expanding List |
167+
| rootHeight | max height of scroll component | 400 |
168+
| renderAhead | number of buffered items at the top/bottom | 2 |
169+
| estimatedHeight | approximated value of each row height | 30 |
170+
| expandedGroup | key of expanded group - only for ExpandingList | '' |
171+
172+
Events:
173+
174+
- expand: click event for group element which toggles between visible state of group items - only for ExpandingList
175+
176+
177+
## License
178+
179+
[MIT](http://opensource.org/licenses/MIT)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-windowing",
3-
"version": "0.2.0",
3+
"version": "0.3.0",
44
"description": "",
55
"main": "dist/vue-windowing.ssr.js",
66
"browser": "dist/vue-windowing.esm.js",

src/ExpandingList.vue

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
:estimated-height="estimatedHeight">
77
<template #item="{ item, index}">
88
<div
9-
v-if="headers[index]"
10-
@click="onExpandItem(headers[index])">
9+
v-if="typeof headers[item] !== 'undefined'"
10+
@click="onExpandGroup(item)">
1111
<slot
1212
name="group"
1313
:item="item" />
@@ -34,12 +34,12 @@ export default {
3434
type: Object,
3535
default: () => ({}),
3636
},
37-
expandedItem: {
37+
expandedGroup: {
3838
type: [
3939
String,
4040
Number,
4141
],
42-
default: -1,
42+
default: '',
4343
},
4444
rootHeight: {
4545
type: Number,
@@ -64,9 +64,9 @@ export default {
6464
let items = [];
6565
6666
Object.keys(this.items).forEach((key) => {
67-
this.headers[items.length] = key;
67+
this.headers[key] = items.length;
6868
69-
if (Array.isArray(this.items[key]) && key === this.expandedItem) {
69+
if (Array.isArray(this.items[key]) && key === this.expandedGroup) {
7070
// Flattening structure
7171
items = [
7272
...items,
@@ -83,8 +83,8 @@ export default {
8383
},
8484
},
8585
methods: {
86-
onExpandItem(key) {
87-
this.$emit('expand', this.expandedItem === key ? -1 : key);
86+
onExpandGroup(key) {
87+
this.$emit('expand', this.expandedGroup === key ? '' : key);
8888
},
8989
},
9090
};

src/VirtualScroll.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ export default {
5757
cachedHeight: {},
5858
};
5959
},
60+
watch: {
61+
items() {
62+
this.cachedHeight = {};
63+
},
64+
},
6065
computed: {
6166
childPositions() {
6267
const results = [

src/entry.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
// Import vue component
2-
import component from '@/vue-windowing.vue';
3-
42
import VirtualScroll from '@/VirtualScroll';
53
import AutoHeightMeasurer from '@/AutoHeightMeasurer';
64
import ExpandingList from '@/ExpandingList';

src/vue-windowing.vue

Lines changed: 0 additions & 77 deletions
This file was deleted.

0 commit comments

Comments
 (0)