3 * Copyright(c) 2006-2009 Ext JS, LLC
5 * http://www.extjs.com/license
7 // Application instance for showing user-feedback messages.
8 var App = new Ext.App({});
10 // Create a standard HttpProxy instance.
11 var proxy = new Ext.data.HttpProxy({
15 // Typical JsonReader. Notice additional meta-data params for defining the core attributes of your json-response
16 var reader = new Ext.data.JsonReader({
17 totalProperty: 'total',
18 successProperty: 'success',
21 messageProperty: 'message' // <-- New "messageProperty" meta-data
24 {name: 'email', allowBlank: false},
25 {name: 'first', allowBlank: false},
26 {name: 'last', allowBlank: false}
29 // The new DataWriter component.
30 var writer = new Ext.data.JsonWriter({
31 encode: false // <-- don't return encoded JSON -- causes Ext.Ajax#request to send data using jsonData config rather than HTTP params
34 // Typical Store collecting the Proxy, Reader and Writer together.
35 var store = new Ext.data.Store({
37 restful: true, // <-- This Store is RESTful
40 writer: writer // <-- plug a DataWriter into the store just as you would a Reader
43 // load the store immeditately
47 // ***New*** centralized listening of DataProxy events "beforewrite", "write" and "writeexception"
48 // upon Ext.data.DataProxy class. This is handy for centralizing user-feedback messaging into one place rather than
49 // attaching listenrs to EACH Store.
51 // Listen to all DataProxy beforewrite events
53 Ext.data.DataProxy.addListener('beforewrite', function(proxy, action) {
54 App.setAlert(App.STATUS_NOTICE, "Before " + action);
60 Ext.data.DataProxy.addListener('write', function(proxy, action, result, res, rs) {
61 App.setAlert(true, action + ':' + res.message);
65 // all exception events
67 Ext.data.DataProxy.addListener('exception', function(proxy, type, action, options, res) {
68 App.setAlert(false, "Something bad happend while executing " + action);
71 // Let's pretend we rendered our grid-columns with meta-data from our ORM framework.
73 {header: "ID", width: 40, sortable: true, dataIndex: 'id'},
74 {header: "Email", width: 100, sortable: true, dataIndex: 'email', editor: new Ext.form.TextField({})},
75 {header: "First", width: 50, sortable: true, dataIndex: 'first', editor: new Ext.form.TextField({})},
76 {header: "Last", width: 50, sortable: true, dataIndex: 'last', editor: new Ext.form.TextField({})}
80 Ext.onReady(function() {
83 // use RowEditor for editing
84 var editor = new Ext.ux.grid.RowEditor({
88 // Create a typical GridPanel with RowEditor plugin
89 var userGrid = new Ext.grid.GridPanel({
90 renderTo: 'user-grid',
98 columns : userColumns,
105 iconCls: 'silk-delete',
116 function onAdd(btn, ev) {
117 var u = new userGrid.store.recordType({
122 editor.stopEditing();
123 userGrid.store.insert(0, u);
124 editor.startEditing(0);
129 function onDelete() {
130 var rec = userGrid.getSelectionModel().getSelected();
134 userGrid.store.remove(rec);