Ext.onReady(function() {
// creates an Person class - instances of that class
// will be stored in the data store
Ext.define('Person', {
extend: 'Ext.data.Model',
fields: ['firstName', 'lastName']
});
// the proxy to get the data from
// for 'real' applications this should be included in another file
// that way it's possible to exchange between mockup and real data
// by simple exchaning a script include
var peopleProxy = new Ext.data.MemoryProxy({
root: [{
firstName: 'Homer',
lastName: 'Simpson'}]
});
var people = Ext.create('Ext.data.Store', {
model: 'Person',
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'root'
}
}
});
people.load();
grid = Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: people,
columns: [
{
header: 'First name',
width: 100,
dataIndex: 'firstName'},
{
header: 'Last name',
width: 150,
dataIndex: 'lastName'}
]
});
button = Ext.create('Ext.Button', {
text: 'Add Person',
handler: function() {
if (Math.random() < 0.5) {
people.add(new Person({
firstName: 'Ned',
lastName: 'Flanders'
}));
}
else {
people.add(new Person({
firstName: 'C.M.',
lastName: 'Burns'
}));
}
}
});
Ext.create('Ext.Container', {
renderTo: Ext.getBody(),
items: [grid, button]
});
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.