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.

164 lines
5.3 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. /**
  17. * Handler specified for the 'Available' column renderer
  18. * @param {Object} value
  19. */
  20. function formatDate(value){
  21. return value ? value.dateFormat('M d, Y') : '';
  22. }
  23. // shorthand alias
  24. var fm = Ext.form;
  25. // the column model has information about grid columns
  26. // dataIndex maps the column to the specific data field in
  27. // the data store (created below)
  28. var cm = new Ext.grid.ColumnModel({
  29. // specify any defaults for each column
  30. defaults: {
  31. sortable: true // columns are not sortable by default
  32. },
  33. columns: [{
  34. id: 'common',
  35. header: 'Common Name',
  36. dataIndex: 'common',
  37. width: 220,
  38. // use shorthand alias defined above
  39. editor: new fm.TextField({
  40. allowBlank: false
  41. })
  42. }, {
  43. header: 'Light',
  44. dataIndex: 'light',
  45. width: 130,
  46. editor: new fm.ComboBox({
  47. typeAhead: true,
  48. triggerAction: 'all',
  49. // transform the data already specified in html
  50. transform: 'light',
  51. lazyRender: true,
  52. listClass: 'x-combo-list-small'
  53. })
  54. }, {
  55. header: 'Price',
  56. dataIndex: 'price',
  57. width: 70,
  58. align: 'right',
  59. renderer: 'usMoney',
  60. editor: new fm.NumberField({
  61. allowBlank: false,
  62. allowNegative: false,
  63. maxValue: 100000
  64. })
  65. }, {
  66. header: 'Available',
  67. dataIndex: 'availDate',
  68. width: 95,
  69. renderer: formatDate,
  70. editor: new fm.DateField({
  71. format: 'm/d/y',
  72. minValue: '01/01/06',
  73. disabledDays: [0, 6],
  74. disabledDaysText: 'Plants are not available on the weekends'
  75. })
  76. }, {
  77. xtype: 'checkcolumn',
  78. header: 'Indoor?',
  79. dataIndex: 'indoor',
  80. width: 55
  81. }]
  82. });
  83. // create the Data Store
  84. var store = new Ext.data.Store({
  85. // destroy the store if the grid is destroyed
  86. autoDestroy: true,
  87. // load remote data using HTTP
  88. url: 'plants.xml',
  89. // specify a XmlReader (coincides with the XML format of the returned data)
  90. reader: new Ext.data.XmlReader({
  91. // records will have a 'plant' tag
  92. record: 'plant',
  93. // use an Array of field definition objects to implicitly create a Record constructor
  94. fields: [
  95. // the 'name' below matches the tag name to read, except 'availDate'
  96. // which is mapped to the tag 'availability'
  97. {name: 'common', type: 'string'},
  98. {name: 'botanical', type: 'string'},
  99. {name: 'light'},
  100. {name: 'price', type: 'float'},
  101. // dates can be automatically converted by specifying dateFormat
  102. {name: 'availDate', mapping: 'availability', type: 'date', dateFormat: 'm/d/Y'},
  103. {name: 'indoor', type: 'bool'}
  104. ]
  105. }),
  106. sortInfo: {field:'common', direction:'ASC'}
  107. });
  108. // create the editor grid
  109. var grid = new Ext.grid.EditorGridPanel({
  110. store: store,
  111. cm: cm,
  112. renderTo: 'editor-grid',
  113. width: 600,
  114. height: 300,
  115. autoExpandColumn: 'common', // column with this id will be expanded
  116. title: 'Edit Plants?',
  117. frame: true,
  118. clicksToEdit: 1,
  119. tbar: [{
  120. text: 'Add Plant',
  121. handler : function(){
  122. // access the Record constructor through the grid's store
  123. var Plant = grid.getStore().recordType;
  124. var p = new Plant({
  125. common: 'New Plant 1',
  126. light: 'Mostly Shade',
  127. price: 0,
  128. availDate: (new Date()).clearTime(),
  129. indoor: false
  130. });
  131. grid.stopEditing();
  132. store.insert(0, p);
  133. grid.startEditing(0, 0);
  134. }
  135. }]
  136. });
  137. // manually trigger the data store load
  138. store.load({
  139. // store loading is asynchronous, use a load listener or callback to handle results
  140. callback: function(){
  141. Ext.Msg.show({
  142. title: 'Store Load Callback',
  143. msg: 'store was loaded, data available for processing',
  144. modal: false,
  145. icon: Ext.Msg.INFO,
  146. buttons: Ext.Msg.OK
  147. });
  148. }
  149. });
  150. });