List Index

    List Index allows to access a particular section of the list view instantly without scrolling through each section.

    Single List Index layout is pretty simple:

    List Index App Methods

    Let’s look at related App methods to work with List Index:

    app.listIndex.create(parameters)- create List Index instance

    • parameters - object. Object with list index parameters

    Method returns created List Index’s instance

    • el - HTMLElement or string (with CSS Selector) or object. List Index element or List Index instance to destroy.

    app.listIndex.get(el)- get List Index instance by HTML element

    • el - HTMLElement or string (with CSS Selector). List Index element.

    Method returns List Index’s instance

    Now let’s look at list of available parameters we need to create List Index:

    List Index Methods & Properties

    So to create List Index we have to call:

    1. var listIndex = app.listIndex.create({ /* parameters */ })

    After that we have its initialized instance (like listIndex variable in example above) with useful methods and properties:

    App and List Index Instance Events

    List Index instance emits events on both self instance and app instance. App instance events has same names prefixed with listIndex.

    List Index Auto Initialization

    If you don’t need to use List Index API and your List Index is inside of the page and presented in DOM on moment of page initialization then it can be auto initialized with just adding additional list-index-init class:

    In this case if you need to access created List Index instance you can use the app.listIndex.get app method:

    1. var listIndex = app.listIndex.get('.list-index');
    2. var indexes = listIndex.indexes;
    3. // do something with indexes

    When using auto init you may need to pass additional parameters. you can set all available parameters via data- attributes on list index element:

    1. <div class="page">
    2. ...
    3. <!-- parameters set via data- attributes -->
    4. <div class="list-index"
    5. data-indexes="auto"
    6. ></div>
    7. <div class="page-content">
    8. <div class="list contacts-list">
    9. ...
    10. </div>
    11. </div>
    12. </div>

    Below is the list of related CSS variables (CSS custom properties).

    Examples

    1. <div class="page">
    2. <div class="navbar">
    3. ...
    4. </div>
    5. <!-- List index element -->
    6. <div class="list-index"></div>
    7. <div class="page-content">
    8. <!-- Contacts list -->
    9. <div class="list simple-list contacts-list">
    10. <div class="list-group">
    11. <ul>
    12. <li class="list-group-title">A</li>
    13. <li>Aaron</li>
    14. <li>Adam</li>
    15. ...
    16. </ul>
    17. </div>
    18. <div class="list-group">
    19. <li class="list-group-title">B</li>
    20. <li>Benjamin</li>
    21. <li>Blake</li>
    22. <li>Bobby</li>
    23. </ul>
    24. </div>
    25. <div class="list-group">
    26. <ul>
    27. <li class="list-group-title">C</li>
    28. <li>Caleb</li>
    29. <li>Callum</li>
    30. ...
    31. </ul>
    32. </div>
    33. ...
    34. </div>
    35. </div>
    36. </div>
    1. var app = new Framework7();
    2. var listIndex = app.listIndex.create({
    3. // ".list-index" element
    4. el: '.list-index',
    5. // List el where to look indexes and scroll for
    6. listEl: '.contacts-list',
    7. // Generate indexes automatically based on ".list-group-title" and ".item-divider"
    8. indexes: 'auto',
    9. // Scroll list on indexes click and touchmove
    10. scrollList: true,
    11. // Enable bubble label when swiping over indexes