3 * Copyright(c) 2006-2010 Sencha Inc.
5 * http://www.sencha.com/license
7 Ext.onReady(function(){
11 { name : "Rec 0", column1 : "0", column2 : "0" },
12 { name : "Rec 1", column1 : "1", column2 : "1" },
13 { name : "Rec 2", column1 : "2", column2 : "2" },
14 { name : "Rec 3", column1 : "3", column2 : "3" },
15 { name : "Rec 4", column1 : "4", column2 : "4" },
16 { name : "Rec 5", column1 : "5", column2 : "5" },
17 { name : "Rec 6", column1 : "6", column2 : "6" },
18 { name : "Rec 7", column1 : "7", column2 : "7" },
19 { name : "Rec 8", column1 : "8", column2 : "8" },
20 { name : "Rec 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 firstGridStore = 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 firstGrid = new Ext.grid.GridPanel({
49 ddGroup : 'secondGridDDGroup',
50 store : firstGridStore,
52 enableDragDrop : true,
54 autoExpandColumn : 'name',
58 var secondGridStore = new Ext.data.JsonStore({
63 // create the destination Grid
64 var secondGrid = new Ext.grid.GridPanel({
65 ddGroup : 'firstGridDDGroup',
66 store : secondGridStore,
68 enableDragDrop : true,
70 autoExpandColumn : 'name',
75 //Simple 'border layout' panel to house both grids
76 var displayPanel = new Ext.Panel({
81 defaults : { flex : 1 }, //auto stretch
82 layoutConfig : { align : 'stretch' },
90 text : 'Reset both grids',
91 handler : function() {
93 firstGridStore.loadData(myData);
95 //purge destination grid
96 secondGridStore.removeAll();
102 // used to add records to the destination stores
103 var blankRecord = Ext.data.Record.create(fields);
108 // This will make sure we only drop to the view scroller element
109 var firstGridDropTargetEl = firstGrid.getView().scroller.dom;
110 var firstGridDropTarget = new Ext.dd.DropTarget(firstGridDropTargetEl, {
111 ddGroup : 'firstGridDDGroup',
112 notifyDrop : function(ddSource, e, data){
113 var records = ddSource.dragData.selections;
114 Ext.each(records, ddSource.grid.store.remove, ddSource.grid.store);
115 firstGrid.store.add(records);
116 firstGrid.store.sort('name', 'ASC');
122 // This will make sure we only drop to the view scroller element
123 var secondGridDropTargetEl = secondGrid.getView().scroller.dom;
124 var secondGridDropTarget = new Ext.dd.DropTarget(secondGridDropTargetEl, {
125 ddGroup : 'secondGridDDGroup',
126 notifyDrop : function(ddSource, e, data){
127 var records = ddSource.dragData.selections;
128 Ext.each(records, ddSource.grid.store.remove, ddSource.grid.store);
129 secondGrid.store.add(records);
130 secondGrid.store.sort('name', 'ASC');