app.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**
  2. * @example Row Editing
  3. *
  4. * This grid demonstrates row editing capabilities.
  5. */
  6. Ext.require('Ext.data.Store');
  7. Ext.require('Ext.grid.Panel');
  8. Ext.require('Ext.form.field.Text');
  9. Ext.require('Ext.form.field.Date');
  10. Ext.require('Ext.form.field.Display');
  11. Ext.require('Ext.grid.plugin.RowEditing');
  12. Ext.define('User', {
  13. extend: 'Ext.data.Model',
  14. fields: [
  15. { name: 'name', type: 'string' },
  16. { name: 'email', type: 'string' },
  17. { name: 'phone', type: 'string' },
  18. { name: 'birthDate', type: 'date' }
  19. ]
  20. });
  21. Ext.onReady(function() {
  22. var userStore = Ext.create('Ext.data.Store', {
  23. model: 'User',
  24. data: {
  25. items: [
  26. { name: 'Lisa', email: 'lisa@simpsons.com', phone: '555-111-1224', birthDate: new Date(1981, 9, 28) },
  27. { name: 'Bart', email: 'bart@simpsons.com', phone: '555-222-1234', birthDate: new Date(1979, 4, 1) },
  28. { name: 'Homer', email: 'home@simpsons.com', phone: '555-222-1244', birthDate: new Date(1956, 3, 15) },
  29. { name: 'Marge', email: 'marge@simpsons.com', phone: '555-222-1254', birthDate: new Date(1954, 10, 1) }
  30. ]
  31. },
  32. proxy: {
  33. type: 'memory',
  34. reader: {
  35. type: 'json',
  36. root: 'items'
  37. }
  38. }
  39. });
  40. Ext.create('Ext.grid.Panel', {
  41. renderTo: Ext.getBody(),
  42. store: userStore,
  43. width: 400,
  44. height: 200,
  45. title: 'Application Users',
  46. columns: [
  47. {
  48. text: 'Name',
  49. flex: 1,
  50. hideable: false,
  51. dataIndex: 'name',
  52. editor: {
  53. //use a Ext.form.field.Text as the editor
  54. xtype: 'textfield',
  55. //prevent empty values from being inserted into this field
  56. allowBlank: false
  57. }
  58. },
  59. {
  60. text: 'Email Address',
  61. width: 130,
  62. dataIndex: 'email',
  63. //use a Ext.form.field.Text as the editor
  64. editor: 'textfield'
  65. },
  66. {
  67. text: 'Phone Number',
  68. width: 85,
  69. dataIndex: 'phone'
  70. },
  71. {
  72. text: 'Birth Date',
  73. width: 90,
  74. dataIndex: 'birthDate',
  75. //use a Ext.form.field.Date as the editor
  76. editor: 'datefield',
  77. // format the date using a renderer from the Ext.util.Format class
  78. renderer: Ext.util.Format.dateRenderer('m/d/Y')
  79. }
  80. ],
  81. selType: 'rowmodel',
  82. plugins: [
  83. Ext.create('Ext.grid.plugin.RowEditing', {
  84. clicksToEdit: 1
  85. })
  86. ]
  87. });
  88. });