cell-editing.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. Ext.Loader.setConfig({
  2. enabled: true
  3. });
  4. Ext.Loader.setPath('Ext.ux', '../ux');
  5. Ext.require([
  6. 'Ext.selection.CellModel',
  7. 'Ext.grid.*',
  8. 'Ext.data.*',
  9. 'Ext.util.*',
  10. 'Ext.state.*',
  11. 'Ext.form.*',
  12. 'Ext.ux.CheckColumn'
  13. ]);
  14. if (window.location.search.indexOf('scopecss') !== -1) {
  15. // We are using ext-all-scoped.css, so all rendered ExtJS Components must have a
  16. // reset wrapper round them to provide localized CSS resetting.
  17. Ext.scopeResetCSS = true;
  18. }
  19. Ext.onReady(function(){
  20. Ext.QuickTips.init();
  21. function formatDate(value){
  22. return value ? Ext.Date.dateFormat(value, 'M d, Y') : '';
  23. }
  24. Ext.define('Plant', {
  25. extend: 'Ext.data.Model',
  26. fields: [
  27. // the 'name' below matches the tag name to read, except 'availDate'
  28. // which is mapped to the tag 'availability'
  29. {name: 'common', type: 'string'},
  30. {name: 'botanical', type: 'string'},
  31. {name: 'light'},
  32. {name: 'price', type: 'float'},
  33. // dates can be automatically converted by specifying dateFormat
  34. {name: 'availDate', mapping: 'availability', type: 'date', dateFormat: 'm/d/Y'},
  35. {name: 'indoor', type: 'bool'}
  36. ]
  37. });
  38. // create the Data Store
  39. var store = Ext.create('Ext.data.Store', {
  40. // destroy the store if the grid is destroyed
  41. autoDestroy: true,
  42. model: 'Plant',
  43. proxy: {
  44. type: 'ajax',
  45. // load remote data using HTTP
  46. url: 'plants.xml',
  47. // specify a XmlReader (coincides with the XML format of the returned data)
  48. reader: {
  49. type: 'xml',
  50. // records will have a 'plant' tag
  51. record: 'plant'
  52. }
  53. },
  54. sorters: [{
  55. property: 'common',
  56. direction:'ASC'
  57. }]
  58. });
  59. var cellEditing = Ext.create('Ext.grid.plugin.CellEditing', {
  60. clicksToEdit: 1
  61. });
  62. // create the grid and specify what field you want
  63. // to use for the editor at each header.
  64. var grid = Ext.create('Ext.grid.Panel', {
  65. store: store,
  66. columns: [{
  67. id: 'common',
  68. header: 'Common Name',
  69. dataIndex: 'common',
  70. flex: 1,
  71. editor: {
  72. allowBlank: false
  73. }
  74. }, {
  75. header: 'Light',
  76. dataIndex: 'light',
  77. width: 130,
  78. editor: new Ext.form.field.ComboBox({
  79. typeAhead: true,
  80. triggerAction: 'all',
  81. selectOnTab: true,
  82. store: [
  83. ['Shade','Shade'],
  84. ['Mostly Shady','Mostly Shady'],
  85. ['Sun or Shade','Sun or Shade'],
  86. ['Mostly Sunny','Mostly Sunny'],
  87. ['Sunny','Sunny']
  88. ],
  89. lazyRender: true,
  90. listClass: 'x-combo-list-small'
  91. })
  92. }, {
  93. header: 'Price',
  94. dataIndex: 'price',
  95. width: 70,
  96. align: 'right',
  97. renderer: 'usMoney',
  98. editor: {
  99. xtype: 'numberfield',
  100. allowBlank: false,
  101. minValue: 0,
  102. maxValue: 100000
  103. }
  104. }, {
  105. header: 'Available',
  106. dataIndex: 'availDate',
  107. width: 95,
  108. renderer: formatDate,
  109. editor: {
  110. xtype: 'datefield',
  111. format: 'm/d/y',
  112. minValue: '01/01/06',
  113. disabledDays: [0, 6],
  114. disabledDaysText: 'Plants are not available on the weekends'
  115. }
  116. }, {
  117. xtype: 'checkcolumn',
  118. header: 'Indoor?',
  119. dataIndex: 'indoor',
  120. width: 55,
  121. stopSelection: false
  122. }, {
  123. xtype: 'actioncolumn',
  124. width:30,
  125. sortable: false,
  126. items: [{
  127. icon: '../shared/icons/fam/delete.gif',
  128. tooltip: 'Delete Plant',
  129. handler: function(grid, rowIndex, colIndex) {
  130. store.removeAt(rowIndex);
  131. }
  132. }]
  133. }],
  134. selModel: {
  135. selType: 'cellmodel'
  136. },
  137. renderTo: 'editor-grid',
  138. width: 600,
  139. height: 300,
  140. title: 'Edit Plants?',
  141. frame: true,
  142. tbar: [{
  143. text: 'Add Plant',
  144. handler : function(){
  145. // Create a model instance
  146. var r = Ext.create('Plant', {
  147. common: 'New Plant 1',
  148. light: 'Mostly Shady',
  149. price: 0,
  150. availDate: Ext.Date.clearTime(new Date()),
  151. indoor: false
  152. });
  153. store.insert(0, r);
  154. cellEditing.startEditByPosition({row: 0, column: 0});
  155. }
  156. }],
  157. plugins: [cellEditing]
  158. });
  159. // manually trigger the data store load
  160. store.load({
  161. // store loading is asynchronous, use a load listener or callback to handle results
  162. callback: function(){
  163. Ext.Msg.show({
  164. title: 'Store Load Callback',
  165. msg: 'store was loaded, data available for processing',
  166. modal: false,
  167. icon: Ext.Msg.INFO,
  168. buttons: Ext.Msg.OK
  169. });
  170. }
  171. });
  172. });