SortButton.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**
  2. * @class Ext.multisort.SortButton
  3. * @extends Ext.button.Button
  4. * @author Ed Spencer
  5. *
  6. *
  7. */
  8. Ext.define('Ext.multisort.SortButton', {
  9. extend: 'Ext.button.Button',
  10. alias : 'widget.sortbutton',
  11. config: {
  12. direction: "ASC",
  13. dataIndex: undefined
  14. },
  15. constructor: function(config) {
  16. this.addEvents(
  17. /**
  18. * @event changeDirection
  19. * Fired whenever the user clicks this button to change its direction
  20. * @param {String} direction The new direction (ASC or DESC)
  21. */
  22. 'changeDirection'
  23. );
  24. this.initConfig(config);
  25. this.callParent(arguments);
  26. },
  27. handler: function() {
  28. this.toggleDirection();
  29. },
  30. /**
  31. * Updates the new direction of this button
  32. * @param {String} direction The new direction
  33. */
  34. updateDirection: function(direction) {
  35. this.setIconCls('direction-' + direction.toLowerCase());
  36. this.fireEvent('changeDirection', direction);
  37. },
  38. /**
  39. * Toggles between ASC and DESC directions
  40. */
  41. toggleDirection: function() {
  42. this.setDirection(Ext.String.toggle(this.direction, "ASC", "DESC"));
  43. }
  44. });