You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

149 lines
4.7 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. This file is part of Ext JS 3.4
  3. Copyright (c) 2011-2013 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. This file may be used under the terms of the GNU General Public License version 3.0 as
  7. published by the Free Software Foundation and appearing in the file LICENSE included in the
  8. packaging of this file.
  9. Please review the following information to ensure the GNU General Public License version 3.0
  10. requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  11. If you are unsure which license is appropriate for your use, please contact the sales department
  12. at http://www.sencha.com/contact.
  13. Build date: 2013-04-03 15:07:25
  14. */
  15. Ext.onReady(function(){
  16. var myData = {
  17. records : [
  18. { name : "Rec 0", column1 : "0", column2 : "0" },
  19. { name : "Rec 1", column1 : "1", column2 : "1" },
  20. { name : "Rec 2", column1 : "2", column2 : "2" },
  21. { name : "Rec 3", column1 : "3", column2 : "3" },
  22. { name : "Rec 4", column1 : "4", column2 : "4" },
  23. { name : "Rec 5", column1 : "5", column2 : "5" },
  24. { name : "Rec 6", column1 : "6", column2 : "6" },
  25. { name : "Rec 7", column1 : "7", column2 : "7" },
  26. { name : "Rec 8", column1 : "8", column2 : "8" },
  27. { name : "Rec 9", column1 : "9", column2 : "9" }
  28. ]
  29. };
  30. // Generic fields array to use in both store defs.
  31. var fields = [
  32. {name: 'name', mapping : 'name'},
  33. {name: 'column1', mapping : 'column1'},
  34. {name: 'column2', mapping : 'column2'}
  35. ];
  36. // create the data store
  37. var firstGridStore = new Ext.data.JsonStore({
  38. fields : fields,
  39. data : myData,
  40. root : 'records'
  41. });
  42. // Column Model shortcut array
  43. var cols = [
  44. { id : 'name', header: "Record Name", width: 160, sortable: true, dataIndex: 'name'},
  45. {header: "column1", width: 50, sortable: true, dataIndex: 'column1'},
  46. {header: "column2", width: 50, sortable: true, dataIndex: 'column2'}
  47. ];
  48. // declare the source Grid
  49. var firstGrid = new Ext.grid.GridPanel({
  50. ddGroup : 'secondGridDDGroup',
  51. store : firstGridStore,
  52. columns : cols,
  53. enableDragDrop : true,
  54. stripeRows : true,
  55. autoExpandColumn : 'name',
  56. title : 'First Grid'
  57. });
  58. var secondGridStore = new Ext.data.JsonStore({
  59. fields : fields,
  60. root : 'records'
  61. });
  62. // create the destination Grid
  63. var secondGrid = new Ext.grid.GridPanel({
  64. ddGroup : 'firstGridDDGroup',
  65. store : secondGridStore,
  66. columns : cols,
  67. enableDragDrop : true,
  68. stripeRows : true,
  69. autoExpandColumn : 'name',
  70. title : 'Second Grid'
  71. });
  72. //Simple 'border layout' panel to house both grids
  73. var displayPanel = new Ext.Panel({
  74. width : 650,
  75. height : 300,
  76. layout : 'hbox',
  77. renderTo : 'panel',
  78. defaults : { flex : 1 }, //auto stretch
  79. layoutConfig : { align : 'stretch' },
  80. items : [
  81. firstGrid,
  82. secondGrid
  83. ],
  84. bbar : [
  85. '->', // Fill
  86. {
  87. text : 'Reset both grids',
  88. handler : function() {
  89. //refresh source grid
  90. firstGridStore.loadData(myData);
  91. //purge destination grid
  92. secondGridStore.removeAll();
  93. }
  94. }
  95. ]
  96. });
  97. // used to add records to the destination stores
  98. var blankRecord = Ext.data.Record.create(fields);
  99. /****
  100. * Setup Drop Targets
  101. ***/
  102. // This will make sure we only drop to the view scroller element
  103. var firstGridDropTargetEl = firstGrid.getView().scroller.dom;
  104. var firstGridDropTarget = new Ext.dd.DropTarget(firstGridDropTargetEl, {
  105. ddGroup : 'firstGridDDGroup',
  106. notifyDrop : function(ddSource, e, data){
  107. var records = ddSource.dragData.selections;
  108. Ext.each(records, ddSource.grid.store.remove, ddSource.grid.store);
  109. firstGrid.store.add(records);
  110. firstGrid.store.sort('name', 'ASC');
  111. return true
  112. }
  113. });
  114. // This will make sure we only drop to the view scroller element
  115. var secondGridDropTargetEl = secondGrid.getView().scroller.dom;
  116. var secondGridDropTarget = new Ext.dd.DropTarget(secondGridDropTargetEl, {
  117. ddGroup : 'secondGridDDGroup',
  118. notifyDrop : function(ddSource, e, data){
  119. var records = ddSource.dragData.selections;
  120. Ext.each(records, ddSource.grid.store.remove, ddSource.grid.store);
  121. secondGrid.store.add(records);
  122. secondGrid.store.sort('name', 'ASC');
  123. return true
  124. }
  125. });
  126. });