Panel.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /**
  2. * @class Ext.multisort.Panel
  3. * @extends Ext.panel.Panel
  4. * @author Ed Spencer
  5. *
  6. *
  7. */
  8. Ext.define('Ext.multisort.Panel', {
  9. extend: 'Ext.panel.Panel',
  10. width: 800,
  11. height: 450,
  12. title: 'Multisort DataView',
  13. autoScroll: true,
  14. requires: ['Ext.toolbar.TextItem', 'Ext.view.View'],
  15. initComponent: function() {
  16. this.tbar = Ext.create('Ext.toolbar.Toolbar', {
  17. plugins : Ext.create('Ext.ux.BoxReorderer', {
  18. listeners: {
  19. scope: this,
  20. drop: this.updateStoreSorters
  21. }
  22. }),
  23. defaults: {
  24. listeners: {
  25. scope: this,
  26. changeDirection: this.updateStoreSorters
  27. }
  28. },
  29. items: [{
  30. xtype: 'tbtext',
  31. text: 'Sort on these fields:',
  32. reorderable: false
  33. }, {
  34. xtype: 'sortbutton',
  35. text : 'Type',
  36. dataIndex: 'type'
  37. }, {
  38. xtype: 'sortbutton',
  39. text : 'Name',
  40. dataIndex: 'name'
  41. }]
  42. });
  43. this.items = {
  44. xtype: 'dataview',
  45. tpl: [
  46. '<tpl for=".">',
  47. '<div class="item">',
  48. (!Ext.isIE6? '<img src="../../datasets/touch-icons/{thumb}" />' :
  49. '<div style="position:relative;width:74px;height:74px;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'../../datasets/touch-icons/{thumb}\')"></div>'),
  50. '<h3>{name}</h3>',
  51. '</div>',
  52. '</tpl>'
  53. ],
  54. plugins: [Ext.create('Ext.ux.DataView.Animated')],
  55. itemSelector: 'div.item',
  56. store: Ext.create('Ext.data.Store', {
  57. autoLoad: true,
  58. sortOnLoad: true,
  59. storeId: 'test',
  60. fields: ['name', 'thumb', 'url', 'type'],
  61. proxy: {
  62. type: 'ajax',
  63. url : '../../datasets/sencha-touch-examples.json',
  64. reader: {
  65. type: 'json',
  66. root: ''
  67. }
  68. }
  69. })
  70. };
  71. this.callParent(arguments);
  72. this.updateStoreSorters();
  73. },
  74. /**
  75. * Returns the array of Ext.util.Sorters defined by the current toolbar button order
  76. * @return {Array} The sorters
  77. */
  78. getSorters: function() {
  79. var buttons = this.query('toolbar sortbutton'),
  80. sorters = [];
  81. Ext.Array.each(buttons, function(button) {
  82. sorters.push({
  83. property : button.getDataIndex(),
  84. direction: button.getDirection()
  85. });
  86. });
  87. return sorters;
  88. },
  89. /**
  90. * @private
  91. * Updates the DataView's Store's sorters based on the current Toolbar button configuration
  92. */
  93. updateStoreSorters: function() {
  94. var sorters = this.getSorters(),
  95. view = this.down('dataview');
  96. view.store.sort(sorters);
  97. }
  98. });