You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.9 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. This file is part of Ext JS 3.4
  3. Copyright (c) 2011-2013 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
  7. published by the Free Software Foundation and appearing in the file LICENSE included in the
  8. packaging of this file.
  9. Please review the following information to ensure the GNU General Public License version 3.0
  10. requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  11. If you are unsure which license is appropriate for your use, please contact the sales department
  12. at http://www.sencha.com/contact.
  13. Build date: 2013-04-03 15:07:25
  14. */
  15. Ext.onReady(function(){
  16. // create the Data Store
  17. var store = new Ext.data.Store({
  18. // load using HTTP
  19. url: 'sheldon.xml',
  20. // the return will be XML, so lets set up a reader
  21. reader: new Ext.data.XmlReader({
  22. // records will have an "Item" tag
  23. record: 'Item',
  24. id: 'ASIN',
  25. totalRecords: '@total'
  26. }, [
  27. // set up the fields mapping into the xml doc
  28. // The first needs mapping, the others are very basic
  29. {name: 'Author', mapping: 'ItemAttributes > Author'},
  30. 'Title',
  31. 'Manufacturer',
  32. 'ProductGroup',
  33. // Detail URL is not part of the column model of the grid
  34. 'DetailPageURL'
  35. ])
  36. });
  37. // create the grid
  38. var grid = new Ext.grid.GridPanel({
  39. store: store,
  40. columns: [
  41. {header: "Author", width: 120, dataIndex: 'Author', sortable: true},
  42. {header: "Title", width: 180, dataIndex: 'Title', sortable: true},
  43. {header: "Manufacturer", width: 115, dataIndex: 'Manufacturer', sortable: true},
  44. {header: "Product Group", width: 100, dataIndex: 'ProductGroup', sortable: true}
  45. ],
  46. sm: new Ext.grid.RowSelectionModel({singleSelect: true}),
  47. viewConfig: {
  48. forceFit: true
  49. },
  50. height:210,
  51. split: true,
  52. region: 'north'
  53. });
  54. // define a template to use for the detail view
  55. var bookTplMarkup = [
  56. 'Title: <a href="{DetailPageURL}" target="_blank">{Title}</a><br/>',
  57. 'Author: {Author}<br/>',
  58. 'Manufacturer: {Manufacturer}<br/>',
  59. 'Product Group: {ProductGroup}<br/>'
  60. ];
  61. var bookTpl = new Ext.Template(bookTplMarkup);
  62. var ct = new Ext.Panel({
  63. renderTo: 'binding-example',
  64. frame: true,
  65. title: 'Book List',
  66. width: 540,
  67. height: 400,
  68. layout: 'border',
  69. items: [
  70. grid,
  71. {
  72. id: 'detailPanel',
  73. region: 'center',
  74. bodyStyle: {
  75. background: '#ffffff',
  76. padding: '7px'
  77. },
  78. html: 'Please select a book to see additional details.'
  79. }
  80. ]
  81. })
  82. grid.getSelectionModel().on('rowselect', function(sm, rowIdx, r) {
  83. var detailPanel = Ext.getCmp('detailPanel');
  84. bookTpl.overwrite(detailPanel.body, r.data);
  85. });
  86. store.load();
  87. });