`
a137268431
  • 浏览: 147785 次
文章分类
社区版块
存档分类
最新评论

Drag and Drop from Grid to Grid Example,增加上下、左右移动的功能。

 
阅读更多

版本:extjs 2.3.0

需求:自定义可排序列选择。

例子:http://localhost/ext230/examples/dd/dnd_grid_to_grid.html

封装:暂无,给大家参考下。

效果如图1所示。

图1


c.html:

  1. <html>
  2. <head>
  3. <metahttp-equiv="Content-Type"content="text/html;charset=UTF-8"/>
  4. <title>test</title>
  5. <linkrel="stylesheet"type="text/css"href="./js/extjs/resources/css/ext-all.css"/>
  6. <scripttype="text/javascript"src="./js/extjs/ext-base.js"></script>
  7. <scripttype="text/javascript"src="./js/extjs/ext-all.js"></script>
  8. <scripttype="text/javascript"src="c.js"></script>
  9. </head>
  10. <body>
  11. <h1>DragandDropfromGridtoGridExample</h1>
  12. <p>ThisexampleshowshowtosetuptwowaydraganddropfromoneGridPaneltoanother.</p>
  13. <p>Notethatthejsisnotminifiedsoitisreadable.See<ahref="dnd_grid_to_grid.js">dnd_grid_to_grid.js</a>.</p>
  14. <divid="panel"></div>
  15. </body>
  16. </html>

c.js

[javascript]view plaincopy
  1. /*
  2. *ExtJSLibrary2.3.0
  3. *Copyright(c)2006-2009,ExtJS,LLC.
  4. *licensing@extjs.com
  5. *
  6. *http://extjs.com/license
  7. */
  8. Ext.onReady(function(){
  9. Ext.QuickTips.init();
  10. varmyData={
  11. records:[
  12. {name:"名称0",column1:"0",column2:"0"},
  13. {name:"名称1",column1:"1",column2:"1"},
  14. {name:"名称2",column1:"2",column2:"2"},
  15. {name:"名称3",column1:"3",column2:"3"},
  16. {name:"名称4",column1:"4",column2:"4"},
  17. {name:"名称5",column1:"5",column2:"5"},
  18. {name:"名称6",column1:"6",column2:"6"},
  19. {name:"名称7",column1:"7",column2:"7"},
  20. {name:"名称8",column1:"8",column2:"8"},
  21. {name:"名称9",column1:"9",column2:"9"},
  22. {name:"名称10",column1:"9",column2:"9"},
  23. {name:"名称11",column1:"9",column2:"9"},
  24. {name:"名称12",column1:"9",column2:"9"},
  25. {name:"名称13",column1:"9",column2:"9"},
  26. {name:"名称14",column1:"9",column2:"9"},
  27. {name:"名称15",column1:"9",column2:"9"},
  28. {name:"名称16",column1:"9",column2:"9"},
  29. {name:"名称17",column1:"9",column2:"9"},
  30. {name:"名称18",column1:"9",column2:"9"},
  31. {name:"名称19",column1:"9",column2:"9"}
  32. ]
  33. };
  34. //Genericfieldsarraytouseinbothstoredefs.
  35. varfields=[
  36. {name:'name',mapping:'name'},
  37. {name:'column1',mapping:'column1'},
  38. {name:'column2',mapping:'column2'}
  39. ];
  40. //createthedatastore
  41. varfirstGridStore=newExt.data.JsonStore({
  42. fields:fields,
  43. data:myData,
  44. root:'records'
  45. });
  46. //ColumnModelshortcutarray
  47. varcols=[
  48. {id:'name',header:"列名称",
  49. //width:160,
  50. sortable:true,
  51. dataIndex:'name'
  52. }//,
  53. //{header:"column1",width:50,sortable:true,dataIndex:'column1'},
  54. //{header:"column2",width:50,sortable:true,dataIndex:'column2'}
  55. ];
  56. //declarethesourceGrid
  57. varfirstGrid=newExt.grid.GridPanel({
  58. ddGroup:'secondGridDDGroup',
  59. store:firstGridStore,
  60. columns:cols,
  61. enableDragDrop:true,
  62. stripeRows:true,
  63. autoExpandColumn:'name',
  64. //width:325,
  65. height:272,
  66. columnWidth:0.4,
  67. //region:'west',
  68. title:'待选择列'
  69. });
  70. varsecondGridStore=newExt.data.JsonStore({
  71. fields:fields,
  72. root:'records'
  73. });
  74. //createthedestinationGrid
  75. varsecondGrid=newExt.grid.GridPanel({
  76. ddGroup:'firstGridDDGroup',
  77. store:secondGridStore,
  78. columns:cols,
  79. enableDragDrop:true,
  80. stripeRows:true,
  81. autoExpandColumn:'name',
  82. height:272,
  83. columnWidth:0.4,
  84. title:'已选择列'
  85. });
  86. varlrPanel={
  87. columnWidth:0.1,
  88. height:300,
  89. items:[
  90. newExt.Button({
  91. text:">",
  92. style:'margin:70px0px0px15px',
  93. handler:function(){
  94. if(firstGrid.getSelectionModel().hasSelection())
  95. {
  96. //数据行数
  97. vartotal=secondGridStore.getCount();
  98. varrecords=firstGrid.getSelectionModel().getSelections();
  99. for(vari=0;i<records.length;i++){
  100. varrecord=records[i];
  101. firstGridStore.remove(record);
  102. secondGridStore.insert(total+i,record);
  103. }
  104. }
  105. }
  106. }),
  107. newExt.Button({
  108. text:">>",
  109. style:'margin:15px0px0px15px',
  110. handler:function(){
  111. //数据行数
  112. vartotal=secondGridStore.getCount();
  113. vari=0;
  114. while(firstGridStore.getCount()>0)
  115. {
  116. varrecord=firstGridStore.getAt(0);
  117. firstGridStore.remove(record);
  118. secondGridStore.insert(total+i,record);
  119. i++;
  120. }
  121. }
  122. }),
  123. newExt.Button({
  124. text:"<",
  125. style:'margin:15px0px0px15px',
  126. handler:function(){
  127. if(secondGrid.getSelectionModel().hasSelection())
  128. {
  129. //数据行数
  130. vartotal=firstGridStore.getCount();
  131. varrecords=secondGrid.getSelectionModel().getSelections();
  132. for(vari=0;i<records.length;i++){
  133. varrecord=records[i];
  134. secondGridStore.remove(record);
  135. firstGridStore.insert(total+i,record);
  136. }
  137. }
  138. }
  139. }),
  140. newExt.Button({
  141. text:"<<",
  142. style:'margin:15px0px0px15px',
  143. handler:function(){
  144. //数据行数
  145. vartotal=firstGridStore.getCount();
  146. vari=0;
  147. while(secondGridStore.getCount()>0)
  148. {
  149. varrecord=secondGridStore.getAt(0);
  150. secondGridStore.remove(record);
  151. firstGridStore.insert(total+i,record);
  152. i++;
  153. }
  154. }
  155. })
  156. ]
  157. };
  158. varudPanel={
  159. columnWidth:0.1,
  160. height:300,
  161. items:[
  162. newExt.Button({
  163. text:"向上",
  164. style:'margin:90px0px0px10px',
  165. handler:function(){
  166. if(secondGrid.getSelectionModel().hasSelection())
  167. {
  168. varrecord=secondGrid.getSelectionModel().getSelected();
  169. //数据行数
  170. vartotal=secondGridStore.getCount();
  171. for(vari=0;i<total-1;i++){
  172. vartemp=secondGridStore.getAt(i);
  173. if(temp.get('name')==record.get('name'))
  174. {
  175. break;
  176. }
  177. varnext=secondGridStore.getAt(i+1);
  178. if(next.get('name')==record.get('name'))
  179. {
  180. secondGridStore.remove(next);
  181. secondGridStore.insert(i,next);
  182. }
  183. }
  184. }
  185. }
  186. }),
  187. newExt.Button({
  188. text:"向下",
  189. style:'margin:15px0px0px10px',
  190. handler:function(){
  191. if(secondGrid.getSelectionModel().hasSelection())
  192. {
  193. varrecord=secondGrid.getSelectionModel().getSelected();
  194. //数据行数
  195. vartotal=secondGridStore.getCount();
  196. for(vari=0;i<total-1;i++){
  197. varnext=secondGridStore.getAt(i);
  198. if(next.get('name')==record.get('name'))
  199. {
  200. secondGridStore.remove(next);
  201. secondGridStore.insert(i+1,next);
  202. }
  203. }
  204. }
  205. }
  206. })
  207. ]
  208. };
  209. //Simple'borderlayout'paneltohousebothgrids
  210. vardisplayPanel=newExt.Panel({
  211. width:650,
  212. height:300,
  213. //layout:'border',
  214. layout:'column',
  215. renderTo:'panel',
  216. items:[
  217. firstGrid,
  218. lrPanel,
  219. secondGrid,
  220. udPanel
  221. ],
  222. bbar:[
  223. '->',//Fill
  224. {
  225. text:'确定',
  226. handler:function(){
  227. //数据行数
  228. vartotal=secondGridStore.getCount();
  229. varresults="";
  230. if(total>0)
  231. {
  232. for(vari=0;i<total;i++)
  233. {
  234. varrecord=secondGridStore.getAt(i);
  235. results+=record.get("name")+",";
  236. }
  237. results=results.substring(0,results.length-1);
  238. }
  239. alert("选择的列名称:"+results);
  240. }
  241. },
  242. {
  243. text:'重置',
  244. handler:function(){
  245. //refreshsourcegrid
  246. firstGridStore.loadData(myData);
  247. //purgedestinationgrid
  248. secondGridStore.removeAll();
  249. }
  250. }
  251. ]
  252. });
  253. //usedtoaddrecordstothedestinationstores
  254. varblankRecord=Ext.data.Record.create(fields);
  255. /****
  256. *SetupDropTargets
  257. ***/
  258. //Thiswillmakesureweonlydroptotheviewcontainer
  259. varfirstGridDropTargetEl=firstGrid.getView().el.dom.childNodes[0].childNodes[1];
  260. varfirstGridDropTarget=newExt.dd.DropTarget(firstGridDropTargetEl,{
  261. ddGroup:'firstGridDDGroup',
  262. copy:true,
  263. notifyDrop:function(ddSource,e,data){
  264. //Genericfunctiontoaddrecords.
  265. functionaddRow(record,index,allItems){
  266. //Searchforduplicates
  267. varfoundItem=firstGridStore.find('name',record.data.name);
  268. //ifnotfound
  269. if(foundItem==-1){
  270. firstGridStore.add(record);
  271. //Callasortdynamically
  272. //firstGridStore.sort('name','ASC');
  273. //RemoveRecordfromthesource
  274. ddSource.grid.store.remove(record);
  275. }
  276. }
  277. //Loopthroughtheselections
  278. Ext.each(ddSource.dragData.selections,addRow);
  279. return(true);
  280. }
  281. });
  282. //Thiswillmakesureweonlydroptotheviewcontainer
  283. varsecondGridDropTargetEl=secondGrid.getView().el.dom.childNodes[0].childNodes[1]
  284. vardestGridDropTarget=newExt.dd.DropTarget(secondGridDropTargetEl,{
  285. ddGroup:'secondGridDDGroup',
  286. copy:false,
  287. notifyDrop:function(ddSource,e,data){
  288. //Genericfunctiontoaddrecords.
  289. functionaddRow(record,index,allItems){
  290. //Searchforduplicates
  291. varfoundItem=secondGridStore.find('name',record.data.name);
  292. //ifnotfound
  293. if(foundItem==-1){
  294. secondGridStore.add(record);
  295. //Callasortdynamically
  296. //secondGridStore.sort('name','ASC');
  297. //RemoveRecordfromthesource
  298. ddSource.grid.store.remove(record);
  299. }
  300. }
  301. //Loopthroughtheselections
  302. Ext.each(ddSource.dragData.selections,addRow);
  303. return(true);
  304. }
  305. });
  306. });
分享到:
评论

相关推荐

    DBGridPro new

    For example, you can specify the color, style, and font for every element of the grid, define the type and style of lines. Enforcing application look and feel standards is much easier using the ...

    AJAX and PHP.pdf

    into websites, such as real-time data validation, drag-and-drop, and other tasks that weren't traditionally associated with web applications. Although the AJAX ingredients are mature (the ...

    BCGControlBarPro.v12.00

    BCGPGridExample: added new visual managers and new 2 tabs: "Drag and Drop" and "Easy Input" BCGPIE7Demo: the tab control was fully redesigned and derived from the library MDI Tab control. ...

    plsqldev12.0.6.1832x32主程序+ v12中文包+keygen

    Double-click on an item to paste the text in the cursor location of the current editor or drag & drop it to a specific location in an editor. You can use the editor preferences to configure when and...

    plsqldev12.0.6.1832x64主程序+ v12中文包+keygen

    Double-click on an item to paste the text in the cursor location of the current editor or drag & drop it to a specific location in an editor. You can use the editor preferences to configure when and...

    PLSQL.Developer(X32) v12.0.1.1814主程序+ v11中文包+keygen

    Double-click on an item to paste the text in the cursor location of the current editor or drag & drop it to a specific location in an editor. You can use the editor preferences to configure when and ...

    plsqldev12.0.4.1826x32主程序+ v12中文包+keygen

    Double-click on an item to paste the text in the cursor location of the current editor or drag & drop it to a specific location in an editor. You can use the editor preferences to configure when and...

    PLSQL.Developer(X64) v12.0.1.1814 主程序+ v11中文包+keygen

    Double-click on an item to paste the text in the cursor location of the current editor or drag & drop it to a specific location in an editor. You can use the editor preferences to configure when and ...

    plsqldev12.0.4.1826x64主程序+ v12中文包+keygen

    Double-click on an item to paste the text in the cursor location of the current editor or drag & drop it to a specific location in an editor. You can use the editor preferences to configure when and...

    Android代码-可拖动网格

    An Android ViewGroup that implements a paged grid with drag'n'drop movable items Supports Android 2.2 (API 8) and up Tested on a Nexus One, Galaxy Nexus and a Nexus 7 Example video: v0.1 : ...

    VB编程资源大全(英文源码 其它)

    convertbase.zip VB has built in functions for converting from decimal to Hex and Octal, but nothing for converting from Octal and Hex to decimal (correct us if we are wrong), or from binary to ...

    DevExpress VCL 12.2.6(v2012vol2.6) 源码-例子-帮助-part1

    Q495393 - Card View - Moving a row within a card using drag and drop scrolls the card content up to the first visible row and hides this row under the card bottom edge in certain cases Q487880 - ...

    DevExpress VCL 12.2.6(v2012vol2.6) 源码-例子-帮助-part2

    Q495393 - Card View - Moving a row within a card using drag and drop scrolls the card content up to the first visible row and hides this row under the card bottom edge in certain cases Q487880 - ...

    Visual C++ 编程资源大全(英文源码 控件)

    filedroplistctrl.zip This article explains how to support file drag and drop in your CWnd-derived object(40KB)&lt;END&gt;&lt;br&gt;83,DrivePickerList.zip A control that shows drive names and icons like ...

    WPTools.v6.29.1.Pro

    We recommend to use TMS components to create modern user interfaces, toolbars and ribbons. 19.2.2013 - WPTools 6.29.1 - fix in rtf writing code to solve problem with merged cells - fix possible range...

    Visual C++ 编程资源大全(英文源码 表单)

    (71KB)&lt;END&gt;&lt;br&gt;86,step0.zip A series of articles that resulted from experimenting with adding Drag and Drop features to my existing application. (16KB)&lt;END&gt;&lt;br&gt;87,undo.zip Easily add Undo/Redo ...

    Developing Flex Applications 910p dda_doc88_cracker.zip

    Separating ActionScript from MXML. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 About the Flex development environment. . . . . . . . . . . . . . . . . . . . . . . . . . . . . ...

Global site tag (gtag.js) - Google Analytics