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:
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:
var listIndex = app.listIndex.get('.list-index');
var indexes = listIndex.indexes;
// 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:
<div class="page">
...
<!-- parameters set via data- attributes -->
<div class="list-index"
data-indexes="auto"
></div>
<div class="page-content">
<div class="list contacts-list">
...
</div>
</div>
</div>
Below is the list of related CSS variables (CSS custom properties).
Examples
<div class="page">
<div class="navbar">
...
</div>
<!-- List index element -->
<div class="list-index"></div>
<div class="page-content">
<!-- Contacts list -->
<div class="list simple-list contacts-list">
<div class="list-group">
<ul>
<li class="list-group-title">A</li>
<li>Aaron</li>
<li>Adam</li>
...
</ul>
</div>
<div class="list-group">
<li class="list-group-title">B</li>
<li>Benjamin</li>
<li>Blake</li>
<li>Bobby</li>
</ul>
</div>
<div class="list-group">
<ul>
<li class="list-group-title">C</li>
<li>Caleb</li>
<li>Callum</li>
...
</ul>
</div>
...
</div>
</div>
</div>
var app = new Framework7();
var listIndex = app.listIndex.create({
// ".list-index" element
el: '.list-index',
// List el where to look indexes and scroll for
listEl: '.contacts-list',
// Generate indexes automatically based on ".list-group-title" and ".item-divider"
indexes: 'auto',
// Scroll list on indexes click and touchmove
scrollList: true,
// Enable bubble label when swiping over indexes