-
Notifications
You must be signed in to change notification settings - Fork 0
/
example9.html
90 lines (87 loc) · 2.73 KB
/
example9.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8" />
<title>Using data views [Ext JS Templating Magic]</title>
<script src="ext-3.3.1/adapter/ext/ext-base.js"></script>
<script src="ext-3.3.1/ext-all.js"></script>
<script src="examples.js"></script>
<link rel="stylesheet" type="text/css" href="ext-3.3.1/resources/css/ext-all.css" />
<link rel="stylesheet" type="text/css" href="examples.css" />
<script>
Ext.onReady(function() {
// load the Twitter public timeline
var store = new Ext.data.Store({
autoLoad: true,
proxy: new Ext.data.ScriptTagProxy({
url: 'http://api.twitter.com/1/statuses/public_timeline.json?include_entities=true',
callbackParam: 'callback'
}),
reader: new Ext.data.JsonReader({
idProperty: 'id',
fields: ['id', 'text', 'user']
})
});
var columns = 3;
var template = new Ext.XTemplate(
'<tpl for=".">',
'{[this.groupStart(xindex, \'<div class="group">\')]}',
'<div class="item">',
'<div class="image"><img src="{[values.user.profile_image_url]}"/></div>',
'<div class="name">{[values.user.screen_name]}</div><div class="text">{text}</div>',
'</div>',
'{[this.groupEnd(xindex, xcount, "</div>")]}',
'</tpl>', {
groupStart: function(i, str) {
return (i == 1 || i % columns == 1) ? str : '';
},
groupEnd: function(i, total, str) {
return (i == total || i % columns == 0) ? str : '';
}
}
);
var dataView = new Ext.DataView({
store: store,
tpl: template,
multiSelect: true,
simpleSelect: true,
selectedClass: 'item-selected',
overClass: 'item-over',
itemSelector: 'div.item',
loadingText: 'loading...',
listeners: {
selectionchange: function(view, selected) {
Ext.get('status').update(String.format('{0} selected', selected.length));
}
}
});
dataView.render('list');
// add a keyboard handler to allow column count switching
var map = new Ext.KeyMap(Ext.getDoc(), {
key: '2345',
fn: function(code) {
columns = parseInt(String.fromCharCode(code));
var selected = dataView.getSelectedIndexes();
dataView.refresh();
dataView.select(selected);
},
stopEvent: true
});
});
</script>
</head>
<body id="example9">
<ul id="page-nav">
<li><a rel="index" href="#">index</a></li>
<li><a rel="prev" href="#">←</a></li>
<li><a rel="next" href="#">→</a></li>
</ul>
<h1><a rel="source" href="#">view source</a>Using data views</h1>
<p><b>Press <code>2</code>, <code>3</code>, <code>4</code> or <code>5</code> on your keyboard to change the column count.</b></p>
<div id="status">0 selected</div>
<div id="list"></div>
<div id="footer">
Stefan Gehrig, 2011, to accompany the article "Ext JS templating magic" in <a href="http://jsmag.com"><jsmag></a> 05/2011
</div>
</body>
</html>