/ext-4.0.7/examples/grid/xml-grid.js

https://bitbucket.org/srogerf/javascript · JavaScript · 64 lines · 39 code · 4 blank · 21 comment · 0 complexity · 385648aa204302432692229c77ecd870 MD5 · raw file

  1. /*
  2. This file is part of Ext JS 4
  3. Copyright (c) 2011 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 published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  7. If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
  8. */
  9. Ext.require([
  10. 'Ext.data.*',
  11. 'Ext.grid.*'
  12. ]);
  13. Ext.onReady(function(){
  14. Ext.define('Book',{
  15. extend: 'Ext.data.Model',
  16. fields: [
  17. // set up the fields mapping into the xml doc
  18. // The first needs mapping, the others are very basic
  19. {name: 'Author', mapping: 'ItemAttributes > Author'},
  20. 'Title', 'Manufacturer', 'ProductGroup'
  21. ]
  22. });
  23. // create the Data Store
  24. var store = Ext.create('Ext.data.Store', {
  25. model: 'Book',
  26. autoLoad: true,
  27. proxy: {
  28. // load using HTTP
  29. type: 'ajax',
  30. url: 'sheldon.xml',
  31. // the return will be XML, so lets set up a reader
  32. reader: {
  33. type: 'xml',
  34. // records will have an "Item" tag
  35. record: 'Item',
  36. idProperty: 'ASIN',
  37. totalRecords: '@total'
  38. }
  39. }
  40. });
  41. // create the grid
  42. var grid = Ext.create('Ext.grid.Panel', {
  43. store: store,
  44. columns: [
  45. {text: "Author", flex: 1, dataIndex: 'Author', sortable: true},
  46. {text: "Title", width: 180, dataIndex: 'Title', sortable: true},
  47. {text: "Manufacturer", width: 115, dataIndex: 'Manufacturer', sortable: true},
  48. {text: "Product Group", width: 100, dataIndex: 'ProductGroup', sortable: true}
  49. ],
  50. renderTo:'example-grid',
  51. width: 540,
  52. height: 200
  53. });
  54. });