|
1 | 1 | # vue-windowing |
2 | 2 |
|
3 | 3 | 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) |
0 commit comments