1 | var PresidentsDataStore; |
---|
2 | var PresidentsColumnModel; |
---|
3 | var PresidentListingEditorGrid; |
---|
4 | var PresidentListingWindow; |
---|
5 | |
---|
6 | Ext.onReady(function(){ |
---|
7 | |
---|
8 | Ext.QuickTips.init(); |
---|
9 | |
---|
10 | PresidentsDataStore = new Ext.data.Store({ |
---|
11 | id: 'PresidentsDataStore', |
---|
12 | proxy: new Ext.data.HttpProxy({ |
---|
13 | url: 'database.php', |
---|
14 | method: 'POST' |
---|
15 | }), |
---|
16 | baseParams:{task: "LISTING"}, // this parameter is passed for any HTTP request |
---|
17 | reader: new Ext.data.JsonReader({ |
---|
18 | root: 'results', |
---|
19 | totalProperty: 'total', |
---|
20 | id: 'id' |
---|
21 | },[ |
---|
22 | {name: 'IDpresident', type: 'int', mapping: 'IDpresident'}, |
---|
23 | {name: 'FirstName', type: 'string', mapping: 'firstname'}, |
---|
24 | {name: 'LastName', type: 'string', mapping: 'lastname'}, |
---|
25 | {name: 'IDparty', type: 'int', mapping: 'IDparty'}, |
---|
26 | {name: 'PartyName', type: 'string', mapping: 'name'}, |
---|
27 | {name: 'TookOffice', type: 'date', mapping: 'tookoffice'}, |
---|
28 | {name: 'LeftOffice', type: 'date', mapping: 'leftoffice'}, |
---|
29 | {name: 'Income', type: 'float', mapping: 'income'} |
---|
30 | ]), |
---|
31 | sortInfo:{field: 'IDpresident', direction: "ASC"} |
---|
32 | }); |
---|
33 | |
---|
34 | PresidentsColumnModel = new Ext.grid.ColumnModel( |
---|
35 | [{ |
---|
36 | header: '#', |
---|
37 | readOnly: true, |
---|
38 | dataIndex: 'IDpresident', |
---|
39 | width: 50, |
---|
40 | hidden: false |
---|
41 | },{ |
---|
42 | header: 'First Name', |
---|
43 | dataIndex: 'FirstName', |
---|
44 | width: 60, |
---|
45 | editor: new Ext.form.TextField({ |
---|
46 | allowBlank: false, |
---|
47 | maxLength: 20, |
---|
48 | maskRe: /([a-zA-Z0-9\s]+)$/ |
---|
49 | }) |
---|
50 | },{ |
---|
51 | header: 'Last Name', |
---|
52 | dataIndex: 'LastName', |
---|
53 | width: 80, |
---|
54 | editor: new Ext.form.TextField({ |
---|
55 | allowBlank: false, |
---|
56 | maxLength: 20, |
---|
57 | maskRe: /([a-zA-Z0-9\s]+)$/ |
---|
58 | }) |
---|
59 | },{ |
---|
60 | header: 'ID party', |
---|
61 | readOnly: true, |
---|
62 | dataIndex: 'IDparty', |
---|
63 | width: 50, |
---|
64 | hidden: true |
---|
65 | },{ |
---|
66 | header: 'Party', |
---|
67 | dataIndex: 'PartyName', |
---|
68 | width: 150, |
---|
69 | readOnly: true |
---|
70 | },{ |
---|
71 | header: 'Took Office', |
---|
72 | dataIndex: 'TookOffice', |
---|
73 | width: 80, |
---|
74 | renderer: Ext.util.Format.dateRenderer('m/d/Y'), |
---|
75 | editor: new Ext.form.DateField({ |
---|
76 | format: 'm/d/Y' |
---|
77 | }), |
---|
78 | hidden: false |
---|
79 | },{ |
---|
80 | header: 'Left Office', |
---|
81 | dataIndex: 'LeftOffice', |
---|
82 | width: 80, |
---|
83 | renderer: Ext.util.Format.dateRenderer('m/d/Y'), |
---|
84 | editor: new Ext.form.DateField({ |
---|
85 | format: 'm/d/Y' |
---|
86 | }), |
---|
87 | hidden: false |
---|
88 | },{ |
---|
89 | header: "Income", |
---|
90 | dataIndex: 'Income', |
---|
91 | width: 150, |
---|
92 | renderer: function(v){ return '$ ' + v; }, |
---|
93 | editor: new Ext.form.NumberField({ |
---|
94 | allowBlank: false, |
---|
95 | allowDecimals: true, |
---|
96 | allowNegative: false, |
---|
97 | blankText: '0', |
---|
98 | maxLength: 11 |
---|
99 | }) |
---|
100 | }] |
---|
101 | ); |
---|
102 | PresidentsColumnModel.defaultSortable= true; |
---|
103 | |
---|
104 | PresidentListingEditorGrid = new Ext.grid.EditorGridPanel({ |
---|
105 | id: 'PresidentListingEditorGrid', |
---|
106 | store: PresidentsDataStore, |
---|
107 | cm: PresidentsColumnModel, |
---|
108 | enableColLock:false, |
---|
109 | clicksToEdit:1, |
---|
110 | selModel: new Ext.grid.RowSelectionModel({singleSelect:false}) |
---|
111 | }); |
---|
112 | |
---|
113 | PresidentListingWindow = new Ext.Window({ |
---|
114 | id: 'PresidentListingWindow', |
---|
115 | title: 'The Presidents of the USA', |
---|
116 | closable:true, |
---|
117 | width:700, |
---|
118 | height:350, |
---|
119 | plain:true, |
---|
120 | layout: 'fit', |
---|
121 | items: PresidentListingEditorGrid |
---|
122 | }); |
---|
123 | |
---|
124 | PresidentsDataStore.load(); |
---|
125 | PresidentListingWindow.show(); |
---|
126 | |
---|
127 | }); |
---|