app.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * @example Renderers
  3. *
  4. * This grid demonstrates the use of a couple different custom renderers.
  5. * The birth date field is rendered using a date formatter, and the email address is rendered as a hyperlink.
  6. */
  7. Ext.require('Ext.data.Store');
  8. Ext.require('Ext.grid.Panel');
  9. Ext.define('User', {
  10. extend: 'Ext.data.Model',
  11. fields: [
  12. { name: 'name', type: 'string' },
  13. { name: 'email', type: 'string' },
  14. { name: 'birthDate', type: 'date' }
  15. ]
  16. });
  17. Ext.onReady(function() {
  18. var userStore = Ext.create('Ext.data.Store', {
  19. model: 'User',
  20. data: [
  21. { name: 'Lisa', email: 'lisa@simpsons.com', birthDate: new Date(1981, 9, 28) },
  22. { name: 'Bart', email: 'bart@simpsons.com', birthDate: new Date(1979, 4, 1) },
  23. { name: 'Homer', email: 'home@simpsons.com', birthDate: new Date(1956, 3, 15) },
  24. { name: 'Marge', email: 'marge@simpsons.com', birthDate: new Date(1954, 10, 1) }
  25. ]
  26. });
  27. Ext.create('Ext.grid.Panel', {
  28. renderTo: Ext.getBody(),
  29. store: userStore,
  30. width: 500,
  31. height: 300,
  32. title: 'Application Users',
  33. columns: [
  34. {
  35. text: 'Name',
  36. width: 150,
  37. dataIndex: 'name'
  38. },
  39. {
  40. text: 'Birth Date',
  41. width: 75,
  42. dataIndex: 'birthDate',
  43. // format the date using a renderer from the Ext.util.Format class
  44. renderer: Ext.util.Format.dateRenderer('m/d/Y')
  45. },
  46. {
  47. text: 'Email Address',
  48. flex: 1,
  49. dataIndex: 'email',
  50. // format the email address using a custom renderer
  51. renderer: function(value) {
  52. return Ext.String.format('<a href="mailto:{0}">{1}</a>', value, value);
  53. }
  54. }
  55. ]
  56. });
  57. });