<link href="https://cdnjs.cloudflare.com/ajax/libs/extjs/4.2.1/resources/css/ext-all-neptune-debug.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/extjs/4.2.1/ext-all.min.js"></script>
<div id="countryApp"></div>
var jsonDataUrl = 'http://beta.json-generator.com/api/json/get/CK4M2Hk?indent=2&callback=Ext.data.JsonP.callback1';
Ext.onReady(function() {
Ext.define('app.model.Country', {
extend: 'Ext.data.Model',
fields: [{
name: 'name',
type: 'string'
}, {
name: 'population',
type: 'int'
}]
});
Ext.create('Ext.data.Store', {
storeId: 'countryStore',
model: 'app.model.Country',
autoLoad: true,
proxy: {
type: 'jsonp',
url: jsonDataUrl,
reader: {
type: 'json'
}
}
});
var tpl = new Ext.XTemplate(
'<table class="view_table">',
'<thead>',
'<tr>',
'<th>Name</th>',
'<th>Population</th>',
'</tr>',
'</thead>',
'<tbody>',
'<tpl for=".">',
'<tr>',
'<td>{name}</td>',
'<td>{population}</td>',
'</tr>',
'</tpl>',
'</tbody>',
'</table>'
);
Ext.create('Ext.DataView', {
width : 500,
height : 200,
renderTo : 'countryApp',
store : Ext.getStore('countryStore'),
tpl : tpl
});
});
body {
background: #FFF !important;
}
table {
background: #DDD;
}
thead tr {
background: #9D9;
}
tbody tr:nth-child(2n) {
background: #CFC;
}
tbody tr:nth-child(2n+1) {
background: #EFE;
}
th, td {
width: 100px;
padding: 0.2em;
text-align: center;
}