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. ></Searchbar>
  38. </Subnavbar>
  39. </Navbar>
  40. <Block>
  41. <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>
  42. <p>Here is the example of virtual list with 10 000 items:</p>
  43. </Block>
  44. <List className="searchbar-not-found">
  45. <ListItem title="Nothing found"></ListItem>
  46. </List>
  47. <List
  48. className="searchbar-found"
  49. medialList
  50. virtualList
  51. virtualListParams={{ items: this.state.items, searchAll: this.searchAll, renderExternal: this.renderExternal.bind(this), height: this.$theme.ios ? 63 : 73}}
  52. >
  53. <ul>
  54. {this.state.vlData.items.map((item, index) => (
  55. <ListItem
  56. key={index}
  57. mediaItem
  58. link="#"
  59. title={item.title}
  60. subtitle={item.subtitle}
  61. style={{top: `${this.state.vlData.topPosition}px`}}
  62. ></ListItem>
  63. ))}
  64. </ul>
  65. </List>
  66. </Page>
  67. )
  68. }
  69. }