3 * Copyright(c) 2006-2009 Ext JS, LLC
5 * http://www.extjs.com/license
7 Ext.onReady(function(){
\r
11 { name : "Rec 0", column1 : "0", column2 : "0" },
\r
12 { name : "Rec 1", column1 : "1", column2 : "1" },
\r
13 { name : "Rec 2", column1 : "2", column2 : "2" },
\r
14 { name : "Rec 3", column1 : "3", column2 : "3" },
\r
15 { name : "Rec 4", column1 : "4", column2 : "4" },
\r
16 { name : "Rec 5", column1 : "5", column2 : "5" },
\r
17 { name : "Rec 6", column1 : "6", column2 : "6" },
\r
18 { name : "Rec 7", column1 : "7", column2 : "7" },
\r
19 { name : "Rec 8", column1 : "8", column2 : "8" },
\r
20 { name : "Rec 9", column1 : "9", column2 : "9" }
\r
25 // Generic fields array to use in both store defs.
\r
27 {name: 'name', mapping : 'name'},
\r
28 {name: 'column1', mapping : 'column1'},
\r
29 {name: 'column2', mapping : 'column2'}
\r
32 // create the data store
\r
33 var firstGridStore = new Ext.data.JsonStore({
\r
40 // Column Model shortcut array
\r
42 { id : 'name', header: "Record Name", width: 160, sortable: true, dataIndex: 'name'},
\r
43 {header: "column1", width: 50, sortable: true, dataIndex: 'column1'},
\r
44 {header: "column2", width: 50, sortable: true, dataIndex: 'column2'}
\r
47 // declare the source Grid
\r
48 var firstGrid = new Ext.grid.GridPanel({
\r
49 ddGroup : 'secondGridDDGroup',
\r
50 store : firstGridStore,
\r
52 enableDragDrop : true,
\r
54 autoExpandColumn : 'name',
\r
57 title : 'First Grid'
\r
60 var secondGridStore = new Ext.data.JsonStore({
\r
65 // create the destination Grid
\r
66 var secondGrid = new Ext.grid.GridPanel({
\r
67 ddGroup : 'firstGridDDGroup',
\r
68 store : secondGridStore,
\r
70 enableDragDrop : true,
\r
72 autoExpandColumn : 'name',
\r
75 title : 'Second Grid'
\r
79 //Simple 'border layout' panel to house both grids
\r
80 var displayPanel = new Ext.Panel({
\r
92 text : 'Reset both grids',
\r
93 handler : function() {
\r
94 //refresh source grid
\r
95 firstGridStore.loadData(myData);
\r
97 //purge destination grid
\r
98 secondGridStore.removeAll();
\r
104 // used to add records to the destination stores
\r
105 var blankRecord = Ext.data.Record.create(fields);
\r
108 * Setup Drop Targets
\r
110 // This will make sure we only drop to the view container
\r
111 var firstGridDropTargetEl = firstGrid.getView().el.dom.childNodes[0].childNodes[1];
\r
112 var firstGridDropTarget = new Ext.dd.DropTarget(firstGridDropTargetEl, {
\r
113 ddGroup : 'firstGridDDGroup',
\r
115 notifyDrop : function(ddSource, e, data){
\r
117 // Generic function to add records.
\r
118 function addRow(record, index, allItems) {
\r
120 // Search for duplicates
\r
121 var foundItem = firstGridStore.findExact('name', record.data.name);
\r
123 if (foundItem == -1) {
\r
124 firstGridStore.add(record);
\r
126 // Call a sort dynamically
\r
127 firstGridStore.sort('name', 'ASC');
\r
129 //Remove Record from the source
\r
130 ddSource.grid.store.remove(record);
\r
134 // Loop through the selections
\r
135 Ext.each(ddSource.dragData.selections ,addRow);
\r
141 // This will make sure we only drop to the view container
\r
142 var secondGridDropTargetEl = secondGrid.getView().el.dom.childNodes[0].childNodes[1]
\r
144 var destGridDropTarget = new Ext.dd.DropTarget(secondGridDropTargetEl, {
\r
145 ddGroup : 'secondGridDDGroup',
\r
147 notifyDrop : function(ddSource, e, data){
\r
149 // Generic function to add records.
\r
150 function addRow(record, index, allItems) {
\r
152 // Search for duplicates
\r
153 var foundItem = secondGridStore.findExact('name', record.data.name);
\r
155 if (foundItem == -1) {
\r
156 secondGridStore.add(record);
\r
157 // Call a sort dynamically
\r
158 secondGridStore.sort('name', 'ASC');
\r
160 //Remove Record from the source
\r
161 ddSource.grid.store.remove(record);
\r
164 // Loop through the selections
\r
165 Ext.each(ddSource.dragData.selections ,addRow);
\r