Virtual List - 图1

Virtual List Svelte Component

Virtual List is not a separate Svelte component, but just a particular case of using , Svelte components and special Framework7’s Virtual List component.

Virtual List Properties

PropTypeDefaultDescription
<List> properties
virtualListbooleanfalseEnables Virtual List
virtualListParamsobjectObject with Virtual List Parameters

Virtual List Events

EventDescription
<List> events
virtualItemBeforeInsertEvent will be triggered before item will be added to virtual document fragment
virtualItemsBeforeInsertEvent will be triggered after current DOM list will be removed and before new document will be inserted
virtualItemsAfterInsertEvent will be triggered after new document fragment with items inserted
virtualBeforeClearEvent will be triggered before current DOM list will be removed and replaced with new document fragment

Access To Virtual List Instance

You can access Virtual List initialized instance by accessing .f7VirtualList component’s property.

Examples

Here is the full page example with Virtual List and Searchbar to search through Virtual List items:

  1. <Page>
  2. <Navbar title="Virtual List">
  3. <Subnavbar inner={false}>
  4. <Searchbar
  5. searchContainer=".virtual-list"
  6. searchItem="li"
  7. searchIn=".item-title"
  8. disableButton={!theme.aurora}
  9. ></Searchbar>
  10. </Subnavbar>
  11. </Navbar>
  12. <Block>
  13. <p>Virtual List allows to render lists with huge amount of elements without loss of performance. And it is fully compatible with all Framework7 list components such as Search Bar, Infinite Scroll, Pull To Refresh, Swipeouts (swipe-to-delete) and Sortable.</p>
  14. <p>Here is the example of virtual list with 10 000 items:</p>
  15. </Block>
  16. <List class="searchbar-not-found">
  17. <ListItem title="Nothing found"></ListItem>
  18. </List>
  19. <List
  20. class="searchbar-found"
  21. ul={false}
  22. medialList
  23. virtualList
  24. virtualListParams={{
  25. items: items,
  26. searchAll: searchAll,
  27. renderExternal: renderExternal,
  28. height: theme.ios ? 63 : (theme.md ? 73 : 46)
  29. }}
  30. >
  31. <ul>
  32. {#each vlData.items as item, index (index)}
  33. <ListItem
  34. mediaItem
  35. link="#"
  36. title={item.title}
  37. subtitle={item.subtitle}
  38. style={`top: ${vlData.topPosition}px`}
  39. virtualListIndex={items.indexOf(item)}
  40. ></ListItem>
  41. {/each}
  42. </ul>
  43. </List>
  44. </Page>
  45. <script>
  46. import { theme, Navbar, Page, List, ListItem, Subnavbar, Searchbar, Block } from 'framework7-svelte';
  47. let items = [];
  48. for (let i = 1; i <= 10000; i += 1) {
  49. items.push({
  50. title: `Item ${i}`,
  51. subtitle: `Subtitle ${i}`,
  52. });
  53. }
  54. let vlData = {
  55. items: [],
  56. }
  57. function searchAll(query, items) {
  58. const found = [];
  59. for (let i = 0; i < items.length; i += 1) {
  60. if (items[i].title.toLowerCase().indexOf(query.toLowerCase()) >= 0 || query.trim() === '') found.push(i);
  61. }
  62. return found; // return array with mathced indexes
  63. }
  64. function renderExternal(virtualList, virtualListData) {
  65. vlData = virtualListData;
  66. }
  67. </script>

← View