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
| Ext.onReady(function(){
/******
****** host holds the name of my host computer. I did this because of restrictions on making remote data requests. If the
****** host is localhost, things look great from my development machine. If I try to view my page from another computer,
****** though, I get errors and nothing happens. I set my host to tc-mark-lap (the name of my development computer). If I
****** view my page with localhost in the url, I get an error. If I view it with tc-mark-lap, everything works. This way,
****** I can view pages from my laptop or from a remote machine. I'll have to remember to change this when I deploy to my
****** production server, though. I might be able to set this in my controller or in a config table and use the javascript
****** helper to set it at runtime. I'll have to check on that sometime.
******/
var host = 'tc-mark-lap';
//This is the datastore. My json data will be loaded remotely, then stored in the datastore.
//I used the HttpProxy because I'm accessing data on my local machine
//In my json reader, I define the fields I should get from my json data (id, last_name, first_name, etc.
var ds = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url: 'http://'+host+'/ekklesia3/users/getAllUsers'}), //note that I used host in the url
reader: new Ext.data.JsonReader({
root: 'users',
totalProperty: 'total',
id: 'id'
},[ 'id','last_name', 'first_name', 'address1', 'address2', 'city', 'state', 'zip', 'homePhone', 'cellPhone', 'otherPhone', 'birthdate', 'grade', 'school_id', 'school'])
});
//This is the column model. This defines the columns in my datagrid.
//It also maps each column with the appropriate json data from my database (dataIndex).
var cm = new Ext.grid.ColumnModel([
{id: 'grid-paging', header: "ID",dataIndex: 'id', width: 100, hidden: true},
{header: "Last Name", dataIndex: 'last_name', width: 100},
{header: "First Name", dataIndex: 'first_name', width: 100},
{header: "Address1", dataIndex: 'address1', width: 100},
{header: "Address2", dataIndex: 'address2', width: 100},
{header: "City", dataIndex: 'city', width: 100},
{header: "State", dataIndex: 'state', width: 100},
{header: "Zip", dataIndex: 'zip', width: 100}
]);
//Here's where we define our datagrid. Notice 'grid-paging' -
//that's the div in our layout that we want to render the grid to.
//We also have to specify our dataStore and our columnModel.
//I have no idea what selModel and enableColLock do :-)
var grid = new Ext.grid.EditorGrid('grid-paging', {
ds: ds,
cm: cm,
selModel: new Ext.grid.RowSelectionModel({singleSelect:false}),
enableColLock:false
});
//This sets a layout for our gridpanel div. I'll try to do a tutorial on
//layouts some other time.
var layout = Ext.BorderLayout.create({
center: {
margins:{left:2,top:3,right:2,bottom:3},
panels: [new Ext.GridPanel(grid)]
}
}, 'grid-panel');
grid.render(); //This renders our grid
ds.load(); //This loads data from the database into the datastore.
}) |