binding.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. Ext.require([
  2. 'Ext.grid.*',
  3. 'Ext.data.*',
  4. 'Ext.panel.*',
  5. 'Ext.layout.container.Border'
  6. ]);
  7. Ext.onReady(function(){
  8. Ext.define('Book',{
  9. extend: 'Ext.data.Model',
  10. fields: [
  11. // set up the fields mapping into the xml doc
  12. // The first needs mapping, the others are very basic
  13. {name: 'Author', mapping: 'ItemAttributes > Author'},
  14. 'Title',
  15. 'Manufacturer',
  16. 'ProductGroup',
  17. 'DetailPageURL'
  18. ]
  19. });
  20. // create the Data Store
  21. var store = Ext.create('Ext.data.Store', {
  22. model: 'Book',
  23. proxy: {
  24. // load using HTTP
  25. type: 'ajax',
  26. url: 'sheldon.xml',
  27. // the return will be XML, so lets set up a reader
  28. reader: {
  29. type: 'xml',
  30. record: 'Item',
  31. totalProperty : 'total'
  32. }
  33. }
  34. });
  35. // create the grid
  36. var grid = Ext.create('Ext.grid.Panel', {
  37. store: store,
  38. columns: [
  39. {text: "Author", width: 120, dataIndex: 'Author', sortable: true},
  40. {text: "Title", flex: 1, dataIndex: 'Title', sortable: true},
  41. {text: "Manufacturer", width: 115, dataIndex: 'Manufacturer', sortable: true},
  42. {text: "Product Group", width: 100, dataIndex: 'ProductGroup', sortable: true}
  43. ],
  44. forceFit: true,
  45. height:210,
  46. split: true,
  47. region: 'north'
  48. });
  49. // define a template to use for the detail view
  50. var bookTplMarkup = [
  51. 'Title: <a href="{DetailPageURL}" target="_blank">{Title}</a><br/>',
  52. 'Author: {Author}<br/>',
  53. 'Manufacturer: {Manufacturer}<br/>',
  54. 'Product Group: {ProductGroup}<br/>'
  55. ];
  56. var bookTpl = Ext.create('Ext.Template', bookTplMarkup);
  57. Ext.create('Ext.Panel', {
  58. renderTo: 'binding-example',
  59. frame: true,
  60. title: 'Book List',
  61. width: 540,
  62. height: 400,
  63. layout: 'border',
  64. items: [
  65. grid, {
  66. id: 'detailPanel',
  67. region: 'center',
  68. bodyPadding: 7,
  69. bodyStyle: "background: #ffffff;",
  70. html: 'Please select a book to see additional details.'
  71. }]
  72. });
  73. // update panel body on selection change
  74. grid.getSelectionModel().on('selectionchange', function(sm, selectedRecord) {
  75. if (selectedRecord.length) {
  76. var detailPanel = Ext.getCmp('detailPanel');
  77. bookTpl.overwrite(detailPanel.body, selectedRecord[0].data);
  78. }
  79. });
  80. store.load();
  81. });