Virtual List - 图1

Virtual List React Component

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

Virutal List Properties

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

Virutal 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. export default class extends React.Component {
  2. constructor(props) {
  3. super(props);
  4. const items = [];
  5. for (let i = 1; i <= 10000; i += 1) {
  6. items.push({
  7. title: `Item ${i}`,
  8. subtitle: `Subtitle ${i}`,
  9. });
  10. }
  11. this.state = {
  12. items,
  13. vlData: {
  14. items: [],
  15. },
  16. };
  17. }
  18. searchAll(query, items) {
  19. const found = [];
  20. for (let i = 0; i < items.length; i += 1) {
  21. if (items[i].title.toLowerCase().indexOf(query.toLowerCase()) >= 0 || query.trim() === '') found.push(i);
  22. }
  23. return found; // return array with mathced indexes
  24. }
  25. renderExternal(vl, vlData) {
  26. this.setState({ vlData });
  27. }
  28. render() {
  29. return (
  30. <Page>
  31. <Navbar title="Virtual List" backLink="Back">
  32. <Subnavbar inner={false}>
  33. <Searchbar
  34. searchContainer=".virtual-list"
  35. searchItem="li"
  36. searchIn=".item-title"
  37. disableButton={!this.$theme.aurora}
  38. ></Searchbar>
  39. </Subnavbar>
  40. </Navbar>
  41. <Block>
  42. <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>
  43. <p>Here is the example of virtual list with 10 000 items:</p>
  44. </Block>
  45. <List className="searchbar-not-found">
  46. <ListItem title="Nothing found"></ListItem>
  47. </List>
  48. <List
  49. className="searchbar-found"
  50. medialList
  51. virtualList
  52. virtualListParams={{ items: this.state.items, searchAll: this.searchAll, renderExternal: this.renderExternal.bind(this), height: this.$theme.ios ? 63 : (this.$theme.md ? 73 : 46)}}
  53. >
  54. <ul>
  55. {this.state.vlData.items.map((item, index) => (
  56. <ListItem
  57. key={index}
  58. mediaItem
  59. link="#"
  60. title={item.title}
  61. subtitle={item.subtitle}
  62. style={{top: `${this.state.vlData.topPosition}px`}}
  63. ></ListItem>
  64. ))}
  65. </ul>
  66. </List>
  67. </Page>
  68. )
  69. }
  70. }