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.

122 lines
4.1 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 toolbar = new Ext.Toolbar({
  17. renderTo: 'docbody',
  18. plugins : [
  19. new Ext.ux.ToolbarDroppable({
  20. createItem: function(data) {
  21. var record = data.draggedRecord;
  22. return new Ext.Button({
  23. text : record.get('company'),
  24. iconCls: record.get('change') > 0 ? 'money-up' : 'money-down',
  25. reorderable: true
  26. });
  27. }
  28. }),
  29. new Ext.ux.ToolbarReorderer({defaultReorderable: false})
  30. ],
  31. items: ['Drag items here:']
  32. });
  33. // sample static data for the store
  34. var myData = [
  35. [1, '3m Co',71.72,0.02,0.03,'9/1 12:00am'],
  36. [2, 'Alcoa',29.01,0.42,1.47,'9/1 12:00am'],
  37. [3, 'Altria Group',83.81,-0.28,0.34,'9/1 12:00am'],
  38. [4, 'American Express',52.55,0.01,0.02,'9/1 12:00am'],
  39. [5, 'Microsoft',25.84,-0.14,0.54,'9/1 12:00am'],
  40. [6, 'Pfizer Inc',27.96,-0.4,1.45,'9/1 12:00am'],
  41. [7, 'Coca-Cola',45.07,0.26,0.58,'9/1 12:00am'],
  42. [8, 'Home Depot.',34.64,0.35,1.02,'9/1 12:00am'],
  43. [9, 'Procter & Gamble',61.91,0.01,0.02,'9/1 12:00am'],
  44. [10, 'United Technologies',63.26,-0.55,0.88,'9/1 12:00am'],
  45. [11, 'Verizon Communications',35.57,0.39,1.11,'9/1 12:00am'],
  46. [12, 'Wal-Mart Stores',45.45,-0.73,1.63,'9/1 12:00am']
  47. ];
  48. // create the data store
  49. var store = new Ext.data.ArrayStore({
  50. fields: [
  51. {name: 'id'},
  52. {name: 'company'},
  53. {name: 'price', type: 'float'},
  54. {name: 'change', type: 'float'},
  55. {name: 'pctChange', type: 'float'},
  56. {name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia'}
  57. ]
  58. });
  59. store.loadData(myData);
  60. var dataview = new Ext.DataView({
  61. emptyText: 'No items to display',
  62. singleSelect: true,
  63. autoScroll: true,
  64. overClass: 'x-view-over',
  65. itemSelector: 'div.company',
  66. store: store,
  67. tpl: new Ext.XTemplate(
  68. '<tpl for=".">',
  69. '<div class="company">',
  70. '<h3>{company}</h3>',
  71. '<p class="{[values.change > 0 ? "up" : "down"]}">{[values.change > 0 ? "Up" : "Down"]} {pctChange} since {lastChange:date("d/m/Y")}',
  72. '</div>',
  73. '</tpl>'
  74. )
  75. });
  76. dataview.on('render', function(v) {
  77. dataview.dragZone = new Ext.dd.DragZone(v.getEl(), {
  78. getDragData: function(e) {
  79. var sourceEl = e.getTarget(v.itemSelector, 10);
  80. if (sourceEl) {
  81. d = sourceEl.cloneNode(true);
  82. d.id = Ext.id();
  83. return {
  84. ddel: d,
  85. sourceEl: sourceEl,
  86. repairXY: Ext.fly(sourceEl).getXY(),
  87. sourceStore: v.store,
  88. draggedRecord: v.getRecord(sourceEl)
  89. };
  90. }
  91. },
  92. getRepairXY: function() {
  93. return this.dragData.repairXY;
  94. }
  95. });
  96. });
  97. new Ext.Panel({
  98. renderTo: 'docbody',
  99. tbar : toolbar,
  100. border : true,
  101. width : 600,
  102. height : 400,
  103. layout : 'fit',
  104. items : dataview
  105. });
  106. });