3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
17 Ext.onReady(function(){
20 { name : "Record 0", column1 : "0", column2 : "0" },
21 { name : "Record 1", column1 : "1", column2 : "1" },
22 { name : "Record 2", column1 : "2", column2 : "2" },
23 { name : "Record 3", column1 : "3", column2 : "3" },
24 { name : "Record 4", column1 : "4", column2 : "4" },
25 { name : "Record 5", column1 : "5", column2 : "5" },
26 { name : "Record 6", column1 : "6", column2 : "6" },
27 { name : "Record 7", column1 : "7", column2 : "7" },
28 { name : "Record 8", column1 : "8", column2 : "8" },
29 { name : "Record 9", column1 : "9", column2 : "9" }
32 // Generic fields array to use in both store defs.
33 Ext.define('DataObject', {
34 extend: 'Ext.data.Model',
36 {name: 'name', mapping : 'name'},
37 {name: 'column1', mapping : 'column1'},
38 {name: 'column2', mapping : 'column2'}
42 // create the data store
43 var gridStore = Ext.create('Ext.data.Store', {
48 // Column Model shortcut array
50 { id : 'name', flex: 1, header: "Record Name", sortable: true, dataIndex: 'name'},
51 {header: "column1", width: 50, sortable: true, dataIndex: 'column1'},
52 {header: "column2", width: 50, sortable: true, dataIndex: 'column2'}
55 // declare the source Grid
56 var grid = Ext.create('Ext.grid.Panel', {
59 ddGroup: 'GridExample',
60 ptype: 'gridviewdragdrop',
66 enableDragDrop : true,
72 selModel : Ext.create('Ext.selection.RowModel', {singleSelect : true})
75 // Declare the text fields. This could have been done inline, is easier to read
76 // for folks learning :)
77 var textField1 = Ext.create('Ext.form.field.Text', {
78 fieldLabel : 'Record Name',
82 var textField2 = Ext.create('Ext.form.field.Text', {
83 fieldLabel : 'Column 1',
87 var textField3 = Ext.create('Ext.form.field.Text', {
88 fieldLabel : 'Column 2',
92 // Setup the form panel
93 var formPanel = Ext.create('Ext.form.Panel', {
95 title : 'Generic Form Panel',
96 bodyStyle : 'padding: 10px; background-color: #DFE8F6',
107 //Simple 'border layout' panel to house both grids
108 var displayPanel = Ext.create('Ext.Panel', {
121 text : 'Reset Example',
122 handler : function() {
123 //refresh source grid
124 gridStore.loadData(myData);
125 formPanel.getForm().reset();
135 // This will make sure we only drop to the view container
136 var formPanelDropTargetEl = formPanel.body.dom;
138 var formPanelDropTarget = Ext.create('Ext.dd.DropTarget', formPanelDropTargetEl, {
139 ddGroup: 'GridExample',
140 notifyEnter: function(ddSource, e, data) {
142 //Add some flare to invite drop.
143 formPanel.body.stopAnimation();
144 formPanel.body.highlight();
146 notifyDrop : function(ddSource, e, data){
148 // Reference the record (single selection) for readability
149 var selectedRecord = ddSource.dragData.records[0];
151 // Load the record into the form
152 formPanel.getForm().loadRecord(selectedRecord);
154 // Delete record from the source store. not really required.
155 ddSource.view.store.remove(selectedRecord);