3 * Copyright(c) 2006-2009 Ext JS, LLC
5 * http://www.extjs.com/license
7 Ext.onReady(function(){
11 { name : "Record 0", column1 : "0", column2 : "0" },
12 { name : "Record 1", column1 : "1", column2 : "1" },
13 { name : "Record 2", column1 : "2", column2 : "2" },
14 { name : "Record 3", column1 : "3", column2 : "3" },
15 { name : "Record 4", column1 : "4", column2 : "4" },
16 { name : "Record 5", column1 : "5", column2 : "5" },
17 { name : "Record 6", column1 : "6", column2 : "6" },
18 { name : "Record 7", column1 : "7", column2 : "7" },
19 { name : "Record 8", column1 : "8", column2 : "8" },
20 { name : "Record 9", column1 : "9", column2 : "9" }
25 // Generic fields array to use in both store defs.
27 {name: 'name', mapping : 'name'},
28 {name: 'column1', mapping : 'column1'},
29 {name: 'column2', mapping : 'column2'}
32 // create the data store
33 var gridStore = new Ext.data.JsonStore({
40 // Column Model shortcut array
42 { id : 'name', header: "Record Name", width: 160, sortable: true, dataIndex: 'name'},
43 {header: "column1", width: 50, sortable: true, dataIndex: 'column1'},
44 {header: "column2", width: 50, sortable: true, dataIndex: 'column2'}
47 // declare the source Grid
48 var grid = new Ext.grid.GridPanel({
49 ddGroup : 'gridDDGroup',
52 enableDragDrop : true,
54 autoExpandColumn : 'name',
58 selModel : new Ext.grid.RowSelectionModel({singleSelect : true})
63 // Declare the text fields. This could have been done inline, is easier to read
64 // for folks learning :)
65 var textField1 = new Ext.form.TextField({
66 fieldLabel : 'Record Name',
71 var textField2 = new Ext.form.TextField({
72 fieldLabel : 'Column 1',
77 var textField3 = new Ext.form.TextField({
78 fieldLabel : 'Column 2',
83 // Setup the form panel
84 var formPanel = new Ext.form.FormPanel({
86 title : 'Generic Form Panel',
87 bodyStyle : 'padding: 10px; background-color: #DFE8F6',
99 //Simple 'border layout' panel to house both grids
100 var displayPanel = new Ext.Panel({
112 text : 'Reset Example',
113 handler : function() {
114 //refresh source grid
115 gridStore.loadData(myData);
116 formPanel.getForm().reset();
123 // used to add records to the destination stores
124 var blankRecord = Ext.data.Record.create(fields);
130 // This will make sure we only drop to the view container
131 var formPanelDropTargetEl = formPanel.body.dom;
133 var formPanelDropTarget = new Ext.dd.DropTarget(formPanelDropTargetEl, {
134 ddGroup : 'gridDDGroup',
135 notifyEnter : function(ddSource, e, data) {
137 //Add some flare to invite drop.
138 formPanel.body.stopFx();
139 formPanel.body.highlight();
141 notifyDrop : function(ddSource, e, data){
143 // Reference the record (single selection) for readability
144 var selectedRecord = ddSource.dragData.selections[0];
147 // Load the record into the form
148 formPanel.getForm().loadRecord(selectedRecord);
151 // Delete record from the grid. not really required.
152 ddSource.grid.store.remove(selectedRecord);