Reputation: 3110
I have a sencha template for a data view like the following, where I would like to insert the current number of items in the store. How can I refer to this value in the template or xtemplate?
tpl: "<div class='itineraryCount'>{{count would go here}} entries</div>"
I've tried the API documentation for XTemplate but can't seem to find what I am looking for. Is this possible?
Upvotes: 3
Views: 4136
Reputation: 607
I'm from 2020 and in extjs v.6 in the docs I can see following:
There are some special variables available:
...
xindex: If you are in a "for" or "foreach" looping template, the index of the loop you are in (1-based).
xcount: If you are in a "for" looping template, the total length of the array you are looping.
So, now you can use something like this (if you are in a "for" or "foreach" loop):
tpl: "<div class='itineraryCount'>{[xcount]} entries</div>"
Upvotes: 0
Reputation: 14175
Switch to using a DataView
rather than a plain Panel
to show your count, then you can take advantage of the count value being updated as the store changes automatically, and you can just drop in the length of the values
array into your XTemplate:
new Ext.DataView({
store: YOUR_STORE,
tpl: '<div>{[values.length]}</div>',
itemSelector:'.item',
});
Upvotes: 4