Wednesday, September 2, 2015

Sample ExtJS Grid

In the fiddle demo, I have included ExtJS 5.1.0 in the Frameworks and Extension section and in the External resources section added the following CSS Url,
  1. http://cdn.sencha.com/ext/gpl/4.2.0/resources/css/ext-all.css
Model
  1. Ext.define('User', {
  2. extend: 'Ext.data.Model',
  3. fields: [
  4. { name: 'name', type: 'string' },
  5. { name: 'email', type: 'string' },
  6. { name: 'phone', type: 'string' },
  7. { name: 'Married', type: 'boolean', defaultValue: false }
  8. ]
  9. });
Store
  1. var userStore = Ext.create('Ext.data.Store', {
  2. model: 'User',
  3. data: [
  4. { name: 'Lisa', email: 'lisa@simpsons.com',
  5. phone: '555-111-1224', Married: true },
  6. { name: 'Bart', email: 'bart@simpsons.com',
  7. phone: '555-222-1234', Married: true },
  8. { name: 'Homer', email: 'homer@simpsons.com',
  9. phone: '555-222-1244', Married: false },
  10. { name: 'Marge', email: 'marge@simpsons.com',
  11. phone: '555-222-1254', Married: false }
  12. ]
  13. });
Grid Component
  1. Ext.create('Ext.grid.Panel', {
  2. renderTo: document.body,
  3. store: userStore,
  4. width: 400,
  5. height: 200,
  6. title: 'Application Users',
  7. columns: [
  8. {
  9. text: 'Name',
  10. width: 100,
  11. sortable: false,
  12. hideable: false,
  13. dataIndex: 'name'
  14. },
  15. {
  16. text: 'Email Address',
  17. width: 150,
  18. dataIndex: 'email',
  19. hidden: true
  20. },
  21. {
  22. text: 'Phone Number',
  23. flex: 1,
  24. dataIndex: 'phone'
  25. },
  26. {
  27. xtype: 'booleancolumn',
  28. text: 'Boolean Field',
  29. flex: 1,
  30. dataIndex: 'Married'
  31. }
  32. ]
  33. });
Result
Demo Click here to view in Jsfiddle

No comments:

Post a Comment