SlidingPager.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /**
  2. * @class Ext.ux.SlidingPager
  3. * @extends Object
  4. * Plugin for PagingToolbar which replaces the textfield input with a slider
  5. * @constructor
  6. * Create a new ItemSelector
  7. * @param {Object} config Configuration options
  8. */
  9. Ext.define('Ext.ux.SlidingPager', {
  10. extend: 'Object',
  11. requires: [
  12. 'Ext.slider.Single',
  13. 'Ext.slider.Tip'
  14. ],
  15. constructor : function(config) {
  16. if (config) {
  17. Ext.apply(this, config);
  18. }
  19. },
  20. init : function(pbar){
  21. var idx = pbar.items.indexOf(pbar.child("#inputItem")),
  22. slider;
  23. Ext.each(pbar.items.getRange(idx - 2, idx + 2), function(c){
  24. c.hide();
  25. });
  26. slider = Ext.create('Ext.slider.Single', {
  27. width: 114,
  28. minValue: 1,
  29. maxValue: 1,
  30. hideLabel: true,
  31. tipText: function(thumb) {
  32. return Ext.String.format('Page <b>{0}</b> of <b>{1}</b>', thumb.value, thumb.slider.maxValue);
  33. },
  34. listeners: {
  35. changecomplete: function(s, v){
  36. pbar.store.loadPage(v);
  37. }
  38. }
  39. });
  40. pbar.insert(idx + 1, slider);
  41. pbar.on({
  42. change: function(pb, data){
  43. slider.setMaxValue(data.pageCount);
  44. slider.setValue(data.currentPage);
  45. }
  46. });
  47. }
  48. });